Get a free advice now!

    Pick the topic

    [checkbox* "Developer Outsourcing" "Web developing" "App developing" "Digital Marketing" "eCommerce systems" "eEntertainment systems"]

    Thank you for your message. It has been sent.

    Tags

    Migrating a WP multisite to a single WordPress site

    Migrating a WP multisite to a single WordPress site

    Challenge: move subsite installation of WordPress to a standard single website

    Solution: import MYSQL tables using WP CLI and change the DB prefix in wp-config.php

    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 hosting 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:

    1. import all tables with a particular subsite prefix
    2. change table_prefix in wp-config.php
    3. 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:

    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 .

    Subscribe to our newsletter to stay up-to-date with the latest tips and guidelines.

    Comments
    0 response

    Add comment

    Your email address will not be published. Required fields are marked *

    Popular news

    PHPStorm – fix long load time of a directory window
    • Dev Tips and Tricks

    PHPStorm – fix long load time of a directory window

    January 20, 2023 by createIT
    reCAPTCHA v3 – WordPress implementation
    • Dev Tips and Tricks

    reCAPTCHA v3 – WordPress implementation

    January 20, 2023 by createIT
    How to compare GIT and server files
    • Dev Tips and Tricks

    How to compare GIT and server files

    January 19, 2023 by createIT
    How to trigger a click event inside iframe?
    • Dev Tips and Tricks

    How to trigger a click event inside iframe?

    January 19, 2023 by createIT
    FOOEvents – generate a custom CSV report
    • Dev Tips and Tricks

    FOOEvents – generate a custom CSV report

    January 19, 2023 by createIT
    Headless chrome – testing webgl using playwright
    • Dev Tips and Tricks

    Headless chrome – testing webgl using playwright

    January 18, 2023 by createIT
    Preview big SQL files with PilotEdit
    • Dev Tips and Tricks

    Preview big SQL files with PilotEdit

    January 18, 2023 by createIT
    Outsourcing a team of backend developers
    • Our Highlights

    Outsourcing a team of backend developers

    January 18, 2023 by createIT
    A new look for an aspiring brand
    • Our Highlights

    A new look for an aspiring brand

    January 18, 2023 by createIT
    Percy AI visual regressions – playwright example
    • Dev Tips and Tricks

    Percy AI visual regressions – playwright example

    January 17, 2023 by createIT

    Technology
    Be on the same page as the rest of the industry.

    Contact us