Convert WordPress Single Site to Multisite Subsite with WP-CLI and bash

Converting a WordPress single site to a Multisite subsite can really test your patience levels, especially if you are unfamiliar with the multisite structure. Previously I have shown how to convert a Multisite subsite to a single site. This guide walks you through step by step to convert a WordPress single site to a multisite subsite using WP-CLI and bash tools.

If it any point you struggle with this and want a WordPress single site converted to a multisite subsite for you then feel free to get in touch on Codeable.

Convert WordPress Single Site to Multisite Subsite with WP-CLI and bash

Here in this hypothetical example the single site is stored in this path


I want to convert the guides single site to a subsite for the multisite with this path


Create a temporary folder to store the single site converted to subsite

mkdir -p /tmp/

Prepare Multisite for New Subsite

Enter your multisite root, usually in a similar path to below, remember to change your multisite path (

cd /var/www/

Before getting a list of all subsites here is the basic structure of the folders

InfoSubsite 1 ValuesSubsites > 1 Values
Database prefixwpb_wpb_2_
Plugins folderwp-content/pluginswp-content/plugins
Themes folderwp-content/themeswp-content/themes
Uploads folderwp-content/uploads

Create a new subsite with WP-CLI

wp site create --slug=guides

You will get this formatted output below which provides critical info for converting the WordPress single site to subsite correctly.

Site 2 created:

Get some display information about your multisite installation

wp site list

The blog_id is 2 which the database prefix is made up for the url value subsite

| blog_id | url                                      | last_updated        | registered          |
| 1       |                    | 2017-02-14 16:09:14 | 2017-01-31 11:35:34 |
| 2       |             | 2017-02-21 21:30:15 | 2017-01-31 11:37:04 |

Putting it together the full database prefix for the new guides subsite is wpb_2_

Extracting Database from Single Site and Converting to Subsite

WP-CLI allows you to export database tables specific to each subsite by simulating that the request came from the subsite’s URL.

Enter your single site installation, here /var/www/

cd /var/www/
wp db export --skip-plugins --skip-themes /tmp/singlesite.sql --allow-root

Get the WordPress database prefix from the single site  wp-config.php with grep

grep "table_prefix" wp-config.php

Here wpb_ is the database prefix

Take note of your database prefix here! It will be used in future steps
$table_prefix = 'wpb_';

In case your multisite uses a different database prefix make sure to get that one as well

grep "table_prefix" /var/www/

The subsite database prefix is made up of the multisite prefix wpb_ and the blog_id (subsite id) 2 for the multisite’s subsite

This sed command will replace the database table names replacing the single site prefix with the multisite prefix and blog_id then create a new .sql file

sed "s#wpb_#wbp_2_#g" /tmp/singlesite.sql > /tmp/guides-subsite.sql

If you are copying the database – regardless of your blog_id – to a remote location you can gzip it so it’s much smaller

gzip /tmp/ -c > /tmp/

Packaging WordPress wp-content Folder

We need to compress these folders and extract them to the new multisite installation later

  • WordPress plugins
  • WordPress themes
  • WordPress wp-content uploads which contains images, videos etc for that subsite

Compressing the plugins is done from the multisite root folder

tar -czf /tmp/ -C /var/www/ .

Similarly, compressing the themes folder is done from the multisite root folder

tar -czf /tmp/ -C /var/www/ .

The wp-content uploads folder can be packaged using this tar command

tar -czf /tmp/ -C /var/www/ .

Now you have 3 tar files containing the essential components for your WordPress multisite subsite.

  • /tmp/
  • /tmp/
  • /tmp/

The database has both an sql and gzipped version

  • /tmp/
  • /tmp/

These tars will be extracted to the single site in the next section.

Restore Converted Single Site to Subsite

We need to perform the following tasks to make the converted single site to a multisite subsite

  • Import the WordPress database from single site to subsite
  • Extract wp-content tars from single site to subsite
  • Fix permissions if necessary

Import WordPress Database from Single Site to Subsite

Enter multisite installation with your WordPress files, here it is

cd /var/www/

Import database for the subsite and import it into the WordPress single site installation

wp db import /tmp/

If you happen to have additional problems you may want to read the advanced database search and replacement guide for WordPress.

Extract wp-content to Subsite

Extract the themes.tar.gz to your new single site installation

tar -xf /tmp/ -C /var/www/

Next, extract the plugins.tar.gz to your new single site installation

tar -xf /tmp/ -C /var/www/

Finally, extract the uploads.tar.gz to your new single site installation

The wp-content uploads folder is specific for the subsite using 2 as your blog_id (subsite id) for the 2 subfolder in the uploads/sites folder

tar -xf /tmp/ -C /var/www/

Fix permissions, if www-data isn’t the owner’s user and group change them to the correct values.

sudo chown -R www-data:www-data /var/www/
sudo find /var/www/ -type f -exec chmod 644 {} +
sudo find /var/www/ -type d -exec chmod 755 {} +

The last thing to do is handle the users tables as outlined by Delicious Brains.


tar Directory without Storing Absolute Paths
WP-CLI db tables command
Delicious Brains – Converting Single Site to Multisite Subsite