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.
One thought – when I go to http://www.example.com/staging/wp-admin it automatically redirects me to http://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:
I solved it & it worked 🙂
In
wp_blogs
table ,Old structure was
But i changed it to to make it work as follows:
For root site:
For sub site 1 (any subsite under main site ,I just gave example) :
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.
Add the following line to your wp-config.php file:
define(‘RELOCATE’,true);
Log in, and save your permalinks settings.
Remove the define rule you put in your wp-config.php.
This worked for me.
domain.com
withnewdomain.com
Note: Remember to change domain name inside config.php. Also, copy the .htaccess file to the new server. This is for basic WordPress Multisite with minimal plugins. Try to take a backup first.