How to migrate a standalone WordPress site into a multisite network
We had a few small, independent sites running on the same server that runs our big multisite network. To simplify management and maintenance, I decided to migrate those sites into the multisite network. It turns out the process was relatively straightforward, and I wanted to share how I did it.
Before you begin, you’ll need:
- An existing standalone WordPress site (herein referred to as
source
) - An existing WordPress multisite network (herein referred to as
destination
) - At least one identical admin user on each site (for access and ownership continuity)
Assumptions:
- The site’s URL will remain the same.
- You have at least read access to the source server’s filesystem and SQL DB.
- You have root access to the destination server’s filesystem and SQL DB.
Instructions
Step 1: Prepare the destination
Sign in to the destination network and create a new site. Give the site the same name as the existing site.
Determine the ID of the new site by going to My Sites > Network > Sites
, then hovering over the Edit
link for the site you just created. (You’ll need to know this ID for several steps coming up. From here on out, XX
will stand for this ID number.)
If the site uses a custom theme, be sure to install it on the destination and enable it network-wide.
Copy the uploads folder from the source to the site’s uploads folder on the destination. Note that the destination folder will be /wp-content/uploads/sites/XX/
.
Step 2: Prepare the source DB for migration
Sign in to SQL on the source server.
Determine which database is in use, and list all the tables in it. Copy these tables into a text editor so you can manipulate them. Remove the wp_user
and wp_usermeta
from the list.
Build a command following this pattern to export the tables from SQL. List all of the tables from the previous step here as Table1, Table2, etc. Note, do not export the entire DB otherwise when you import it SQL will drop all other existing tables. This will destroy the multisite network!
mysqldump --user={SQL-USER} --password={SQL-PASSWORD} {DATABASE-NAME} {TABLE1} {TABLE2} ... {TABLE9} > ~/source.sql
Edit the SQL dump file and make the following changes:
- Change all table names to include the ID number of the destination site. For instance,
wp_commentmeta
will becomewp_13_commentmeta
on a destiation site where the site’s ID is13
. - Find and replace all upload paths to correct any attachments. For instance,
/wp-content/uploads/
needs to become/wp-content/uploads/sites/XX/
. - Find the
wp_user_roles
entry in thewp_XX_options
table and change the name of the field towp_XX_user_roles
.
Step 3: Import the source DB on the destination
Back up the entire destination SQL DB so that you can recover from any accidents.
Import the source DB into the destination DB:
mysql --user={SQL-USER} --password={SQL-PASSWORD} {DATABASE-NAME} < source.sql
Browse to the destination site, then go to My Sites > Network > Sites
. Go to the Settings
tab, then ensure SiteURL
and Home
records are using the correct URL.