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:



STEP ONE – Prepare the destination

  1. Sign in to the destination network and create a new site.  Give the site the same name as the existing site.
  2. 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.)
  3. If the site uses a custom theme, be sure to install it on the destination and enable it network-wide.
  4. 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 TWO – Prepare the source DB for migration

  1. Sign in to SQL on the source server.
  2. 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.
  3. 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
  1. Edit the SQL dump file and make the following changes:
    1. Change all table names to include the ID number of the destination site.  For instance, wp_commentmeta will become wp_13_commentmeta on a destiation site where the site's ID is 13.
    2. Find and replace all upload paths to correct any attachments.  For instance, /wp-content/uploads/ needs to be come /wp-content/uploads/sites/XX/.
    3. Find the wp_user_roles entry in the wp_XX_options table and change the name of the field to wp_XX_user_roles.

STEP THREE – Import the source DB on the destination

  1. BACK UP THE ENTIRE DESTINATION SQL DB so that you can recover from any accidents.
  2. Import the source DB into the destination DB:
mysql --user={SQL-USER} --password={SQL-PASSWORD} {DATABASE-NAME} < source.sql
  1. Browse to the destination site, then go to My Sites > Network > Sites.  Go to the Settings tab, then ensure the SiteURL and Home parameters show the correct URL.