Migrate WordPress multisite to new server

WordPress is a free and open source Content Management System written in PHP and is what a vast segment of websites is based on. The platforms has a vary nice feature: it allows the creation and management of multiple websites from the same installation. While migrating a WordPress installation is quite easy, to migrate WordPress multisite to a new server requires additional steps. In this tutorial we see how to proceed.

In this tutorial you will learn:

  • How to backup and restore the site files via ftp
  • How to perform a database migration from the command line or phpmyadmin
  • What parameters needs to be changed to migrate a WordPress multisite installation
Migrate WordPress multisite to new server
Migrate WordPress multisite to new server

Software requirements and conventions used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Distribution independent
Software An ftp client, the mysqldump and mysql command line utility or phpmyadmin
Other None
Conventions # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux-commands to be executed as a regular non-privileged user

How to Migrate WordPress multisite to new server

Step 1 – Creating the backup of the site files

The first step in the migration process consists in the creation of the backup of the original site files. In this case we will perform the operation using an ftp client, since this type of service should be available even on the cheapest hosting platforms.

The ftp credentials (username, password and server url) should have been provided to you when you subscribed your hosting plan. To download the files we need an ftp client. In this example I will use lftp, a very powerful command line client. To connect to the site we issue the following command:

$ lftp <username>:<password>@<url>

Where username is the username used to log in into the ftp server, password is the password associated with said account, and url is the Uniform Resource Locator of the server. The site files are usually contained in the public_html or www directory (the latter is usually a link to the former). To mirror said directory locally with lftp we can use the following command:

~> mirror public_html --parallel=3

Once we execute the command, the public_html directory will be mirrored in our local filesystem. The --parallel option we used above, defines how many files should be downloaded in parallel to speed up the process. In this case we provided a value of 3.

Step 2 – Creating a backup of the database

At this point we should have a backup of our WordPress installation files. What we have to do now, is to create a backup of the database. How to proceed to accomplish this step depends on the services offered by our hosting provider.

Using mysqldump

If the mysql servers is configured to accept remote connections or we can log in to the server via a remote shell, we can use the mysqldump utility to create the backup of our database straight from the command line, with this command:

$ mysqldump \
  --host=<server_hostname> \
  --user=<database_username> \
  --password=<password> \
  <database_name> > bk.sql

The above command will save the SQL instructions needed to recreate the current state of the database into a file called bk.sql. If our hosting provider doesn’t allow database remote access, or we are more comfortable using a graphical interface, we can use a tool like phpmyamdin.

Using phpmyadmin

Phpmyadmin is a web-based mysql administration interface. Usually the service is accessible at the <siteurl>/phpmyadmin address. All we need to do to create a database backup using this tool is to select the database (by clicking on its name), then click on the “Export” tab, select the format in which the backup should be exported and finally click on the “go” button. The file should be ready in few seconds.

Creating a database backup using phpmyadmin
Creating a database backup using phpmyadmin

Step 3 – Uploading the files to the new hosting space

Once we have the files and database backup, we can proceed with the migration to the new hosting space/domain. To upload the files, we use again our favorite ftp client. Supposing we are using lftp, as before, we could run the following command:

~> mirror -R <local_directory> --parallel=3

The command (mirror) is the same we used when we performed the backup, but by using the -R option, we reversed the order of the directories, so that the first one is considered as the local one. In case we want to mirror the directory remotely with another name, we can specify it as the second argument to the command:

~> mirror -R <local_directory> <remote_name> --parallel=3

Step 4 – Restoring the database backup

The method to use to restore the database backup depends, again, on what services we can access to. In case we have ssh or server remote access we can use the mysql command line utility and launch the following command:

$ mysql \
  --user=<database_user> \
  --password=<password> \
  --host=<server_hostname> \
  <database_name> < bk.sql

To restore the backup with phpmyadmin, instead, we select the database which should host the tables and then click on the “Import” tab on the top level menu. We than select the file containing the database backup and finally click on the “go” button at the bottom of the page.

Restoring a database backup with phpmyadmin
Restoring a database backup with phpmyadmin

Step 5 – Changing database values for the new domain

Once we restored the database backup we need to change certain values in some tables. On a WordPress multisite installation tables are repeated for each managed site. Supposing we are managing two websites, for example, we would have the wp_options table repeated for both of them, with specific entries, named progressively (e.g. wp_options, wp_2_options).

Changing “home” and “siteurl” in each site wp_option tables

Inside each site wp_options table, we need to change the value of the option_value column where the value of the option_name one is “siteurl” and “home”, and substitute the old domain with the new one, leaving the site-specific values unaltered, of course. For example, if a site old “siteurl” was https://olddomain.com/siteone, it will become https://newdomain.com/siteone, etc. We can do this with a simple SQL query:

UPDATE wp_options SET option_value = 'https://newdomain.com' WHERE option_name IN ('siteurl', 'home');

Updating the “wp_site”, “wp_sitemeta” and “wp_blogs” tables

Inside the main site wp_site table we need to change the value of the domain column. We want to put our new domain here, without specifying the connection protocol:

UPDATE wp_site SET domain = 'newdomain.com';

Furthermore, in the wp_sitemeta table we need to change the entry in the ‘meta_valuecolumn where themeta_key` is ‘siteurl’:

UPDATE wp_sitemeta SET meta_value = 'https://newdomain.com' WHERE meta_key = 'siteurl';

The last table we need to update is wp_blogs. Here we need to change the value of the domain column for each row:

UPDATE wp_blogs SET domain = 'newdomain.com';

Changing the “wp_configs” file

The last thing we need to do to complete the migration of our multisite WordPress installation is to change some values in the wp_config.php file, which is located in the root directory of the site. Here, as a first thing, we need to update the database connection information and use the new values:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'new_database_name' );

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

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

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

The last thing we need to update in the file is the definition of the DOMAIN_CURRENT_SITE constant (line 87). We need to set it so that it matches the new domain, without any protocol specification:

define('DOMAIN_CURRENT_SITE', 'newdomain');


In this tutorial we saw how to Migrate WordPress multisite to new server. A WordPress multisite installation let us control multiple sites from the same administration interface. We saw how to create a backup of the site files and database and how to restore them, both from the command line tools and with the phpmyadmin web interface. We also saw what values we need to change in the database and in the WordPress configuration in order for the installation to work on the new domain.

Comments and Discussions
Linux Forum