How to migrate a WP multisite to a single WordPress site
We have a multisite WordPress website with a lot of subsites. MS installation uses subfolders as url format.
Examples:
example.com/subsite1
example.com/subsite2
example.com/subsite3
We decided:
- to move each subsite to a standalone WordPress installation without a multisite
- each site will be hosted on separate accounts
- URLs will be configured in: SUBDOMAIN_INSTALL format
The new page urls will use subdomains, examples:
subsite1.example.com
subsite2.example.com
subsite3.example.com
In this tutorial, we will describe step by step how to migrate the WordPress website. The preferred tool is WP CLI, which is fast and easy to use.
Copying all files
The first step is to copy all files to the new hosting:
- WordPress core files
- theme files
- plugin files
- uploads (ex: /wp-content/uploads/sites/3/ → /wp-content/uploads/ )
- add the default WP htaccess
Multisite Database
The WP MS database uses a number prefix for each subsite. We need to export all tables with a particular prefix to create a new standalone installation. To get the list of all sites, we can use the following WP CLI command:
wp site list
Here is the output:
+---------+------------------------------------+---------------------+---------------------+ | blog_id | url | last_updated | registered | +---------+------------------------------------+---------------------+---------------------+ | 1 | https://example.com/subsite1/ | 2021-05-21 14:21:13 | 2020-11-18 13:04:22 | | 3 | https://example.com/subsite2/ | 2022-06-15 22:51:54 | 2020-11-18 13:46:45 | | 4 | https://example.com/subsite3/ | 2022-04-28 08:56:40 | 2020-11-19 11:03:20 | | 5 | https://example.com/subsite4/ | 2022-04-25 13:29:04 | 2022-04-05 11:29:41 | +---------+------------------------------------+---------------------+---------------------+
The first column – blog_id – will tell us which tables should be exported. The site example.com/subsite2 has blog_id set to 3, so we will look for tables that start with the wp_3_ prefix.
3 migration steps
There are only three migration steps that need to be completed to move a multisite website to a single installation:
- import all tables with a particular subsite prefix
- change table_prefix in wp-config.php
- change domains’ urls in the database (replace old urls with new ones)
Export SQL tables
We already know that MYSQL tables that start with the wp_3_ prefix include content of our website. Exporting can be performed using phpMyAdmin or any other MYSQL client (HeidiSQL or Workbench).
An even easier solution is to use the WP CLI command:
wp db export --tables=$(wp db tables --url=example.com/subsite2/ --format=csv --skip-plugins --skip-themes --allow-root) subsite2.sql --allow-root
The result of running this command will be a subsite2.sql file created in the current directory. It will contain all SQL created tables’ definitions and data inserts.
Change the DB prefix
The Wp-config.php file placed in the main WordPress directory is responsible for site configuration. The default value:
$table_prefix = 'wp_';
should be replaced with the new prefix:
$table_prefix = 'wp_3_';
Make sure to set up a table prefix that exists on your old multisite.
Import tables
Use subsite2.sql file to import data to the newly created database. Use your favorite DB Client, or WP CLI command presented here:
wp db import subsite2.sql
WP search-replace urls
Replacing database urls is a standard procedure for migrating WordPress sites. Direct changes in the database are not recommended: strings can be serialized and direct changes can corrupt the database. To replace urls (domains) in the database, there are a couple of recommended tools:
- Better Search Replace – https://github.com/deliciousbrains/better-search-replace
- Search Replace DB – https://github.com/interconnectit/Search-Replace-DB
- WP CLI search-replace
Here is an example of using the command-line interface for WordPress (WP CLI) to replace DB urls:
wp search-replace 'example.com/subsite2' 'subsite2.example.com' --allow-root --all-tables
Summary
That’s it. Only these 3 steps are needed to move your multisite subsite to a single WordPress installation. As a result, your old site example.com/subsite2 will now be working smoothly on the domain: subsite2.example.com .
Interested in enhancing your site’s performance? Learn more by exploring our article on the async plugin WordPress.
Subscribe to our newsletter to stay up-to-date with the latest tips and guidelines.