jxycms
1/16/2017 - 2:10 AM

how to migrate multisite of wordpress

how to migrate multisite of wordpress

How to migrate multisite:

Multisites in Wordpress is a pain in the ass to migrate, it involves several database changes and even when you made everything correct it seems to only work some of the times without errors. However these are the recommended steps:

1. Export database

2. Upload new database

3. Add all your Wordpress files

5. Open wp-config.php. Change database information to:
/** The name of the database for WordPress */
define('DB_NAME', 'exampledb');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', '');

/** MySQL hostname */
define('DB_HOST', 'localhost');
/* Multisite */

define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/example/');

Also, edit these two lines to:
/* Multisite */

define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/example/');

	
7. Edit your htaccess like this (Rewritebase /path/ should be relative path, ie if your website is located at localhost/mypage it should be "RewriteBase /mypage/"):

# MultiSite
RewriteEngine On
RewriteBase /subfolder-from-localhost/
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

8. Database edit time! These steps needs to be done for every subsite your multisite has, if I type change table "wp_site", you should replicate it in wp_site1/wp_site2 etc...

In table wp_options: change fields "site_url" and "home" to (http:)localhost/subfolder (no trailing slash).

In table wp_blogs: change "domain" to "localhost", and "path" for every entry for each subsite to /subfolder/ (must have trailing slash)

In table wp_site: change "domain" to "localhost", and "path" to /subfolder/ (must have trailing slash)

In table wp_sitemeta: change "siteurl" to full path ie (http:)localhost/subfolder/ (must have trailing slash)

9. Now you should atleast have access to your page, if you still get redirection loop or white screen of death, double check the database changes. Now login to admin, and we need to change some hardcoded URLs in the database, I usually do this with a plugin called "Seach and replace", so download and install this plugin, and use it by typing in what it should search for (old url) and what to replace it with (new url).
Search for: http://mysitename.com
Replace with: (http:)localhost

10. Now hopefully you have a functional migration of the multisite. As I noted I've done this a couple of times, and it almost seems random if everything works or not. I'd say I had success with this approach perhaps 6 out of 8 times.