Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here's my setup. I have a Multisite instance running at http://example.com, and I want to do development and staging. Moving an existing Multisite instance of WP onto localhost is a nightmare, so I'm going to do dev on a staging location instead.

I set up http://staging.example.com to point to the /public_html/staging/ directory of the hosting account, and copied all of the WP files from my root into the /staging/ directory. I also copied the database files (SQL dump, imported the tables into a new database), and changed the wp-config.php file to point to the new database.

After running SQL to change the database records, I also change this one line in the wp-config.php file:

/** Turning on WordPress MU, new in 3.0 */
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'example.com' ); // <- I change this line
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Changed to:

define( 'DOMAIN_CURRENT_SITE', 'staging.example.com' ); // <- now changed

When I load up http://staging.example.com, I get... Error establishing database connection!

I've checked and triple checked the username and password, made sure that the user has all privileges on the new staging database, and I've left the DBHOST as 'localhost' (although changing it to staging.example.com didn't help, either).

Why would the database connection fail? Anyone? (Thanks for your help in advance.)

NB: http://example.com is working fine running on very similar db connection settings, just with a different database, so it's not an issue with the database server being down.

share|improve this question
    
Hmm. Nobody, huh? It's a weird error, for sure. –  Jason Rhodes Jul 18 '11 at 21:16
    
I have the same error when trying to do Wordpress Network migration in-place - no host moved –  Mikko Ohtamaa Aug 22 '11 at 7:29
    
Ok. I tracked down various failure modes and made a blog post of them: opensourcehacker.com/2011/08/22/… –  Mikko Ohtamaa Aug 22 '11 at 13:44

2 Answers 2

up vote 2 down vote accepted

One thought - when I go to www.example.com/staging/wp-admin it automatically redirects me to www.example.com/wp-admin

Could the redirect from staging.example.com to example.com/staging be conflicting with the existing install?

UPDATE: looks like it could be related to .htaccess issues and complicated domain references in the database

From the WP Codex:

Moving WordPress Multisite

Multisite is far more complicated to move, as the database itself has multiple references to the server name as well as the folder locations.

The best way to move Multisite is to move the files, edit the .htaccess and wp-config.php (if the folder name containing Multisite changed), and then manually edit the database. Search for all instances of your domain name, and change them as needed. This step cannot yet be easily automated. If you're moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs entries to change the folder name correctly.

share|improve this answer

There is really only one way to do an easy transfer of domain or host that I have found. It works flawlessly for me on single and multisite installations.

  1. Export your database to a .sql file. ( I use PHPMyAdmin for this )
  2. Create a new copy of the file to be edited with a slightly different name.
  3. Open the file in you preferred text editor> ( gedit for example )
  4. Run a find/replace on the domain AND absolute path ( /home/username/public_html/ to /home/username/public_html/ ) from production to dev.
  5. Save the file.
  6. Copy the entire installation to your development directory.
  7. Add the following line to your wp-config.php file:

    define('RELOCATE',true);

  8. Log in, and save your permalinks settings.

  9. Remove the define rule you put in your wp-config.php.

share|improve this answer
1  
That works fine, except if you end up replacing a string in serialized data, such as a widget or theme option, with a string with different length. The serialized data looks like this - s:76:"hxxp://www-dev.example.com/wp-content/uploads/company_logo_swoosh.gif' 's:70:"hxxp://www.example.com/wp-content/uploads/company_logo_swoosh.gif' (note: lengths 76 and 70 no longer correspond to the strings presented - I edited out my site details and didn't keep track of the new character count.) The only solution for that is to manually update the counts - or keep the staging domain length the same. –  marfarma Jul 25 '11 at 18:12
    
I also replaced tt with xx so the urls wouldn't be obscured -- you couldn't see the difference between them. –  marfarma Jul 25 '11 at 18:15
    
That's good to know. This means we should at least take the time to go through all the entries as they are found and replaced instead of replace all. –  Jeff Sebring Jul 25 '11 at 21:50
    
You can use this script to search/replace serialized data: interconnectit.com/products/… –  Costa Oct 14 at 0:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.