Migrating WordPress MultiSite to a New URL

multisiteMigrating WordPress MultiSite to a New URL can be done with a combo of 2 excellent free plugins; WP Migrate DB and BackWPup  the former deals with the database and the latter deals with the files.

The key thing when updating the WordPress database to reflect a new hosting URL is making sure any data serialization stays intact, data serialization involves using the URL in data and if the URL is changed it breaks the data and doesn’t display it. Certain tools like WP Migrate DB take this into account when changing the URL whereas a blanket find and replace in a text editor or a database dump may put you in deep water.

This guide is based on a subfolder WordPress multisite installation,

Installation

Install both plugins in the originating URL and Network Activate them.

Migrating the Database with the New URL

Launch WP Migrate DB via the main admin Dashboard Settings > Migrate DB

wordpress-mutisite-migration

Add in your target URL and home directory webroot path. Take note not to include the webserving protocol in the URL – start with // and also don’t leave trailing slashes in either path.

The advanced options are not required but can be efficient in certain circumstances.

Click on Migrate DB and when done it will pop a gzipped archive in your download folder.

Migrating the Data

wordpress-mutisite-file-migration

Launch BackWPup via main network admin Dashboard and create a new job, just need the files, no need for the database. Save and run now, this plugin has a host of destination options, you can just do it to a local folder and then download when complete.

wordpress-mutisite-file-migration-download

Upload to new URL Destination

Upload both archives to the home directory of the new destination. Uncompress the archives:

Extract the data

tar -xvf files-archive.tar.gz

Remove any database it may have brought with it

rm *.sql

Change files ownership to correct user

chown -R realowner:realowner *

Extract the database

gunzip databasename.sql.gz

Assuming you have a new empty database setup, import the old database

mysql new_databasename < imported_database.sql

The above steps are all command line driven as root, if you don’t have shell access, this will have to be done with phpmyadmin and a ftp app.

 Fix .htaccess and wp-config

Fix up references to the URL in both .htaccess and wp-config

Add in new database connection in wp-config

.htaccess for modern WordPress should resemble

RewriteEngine On
RewriteBase /
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]

 wp-config should include

/* Multisite */
define( 'WP_ALLOW_MULTISITE', false );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'mynewdomain.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
/* That's all, stop editing! Happy bloggin

Make sure and define ‘DOMAIN_CURRENT_SITE’ with the new URL.

That’s it.