Get a free advice now!

    Pick the topic

    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.

    Tags

    How to migrate a WP multisite to a single WordPress site

    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:

    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

    JS react developer – 20 questions for a job interview
    • Technology
    • Trends

    JS react developer – 20 questions for a job interview

    May 24, 2023 by createIT
    PHPStorm – how to replace HTML tags using regex?
    • Dev Tips and Tricks

    PHPStorm – how to replace HTML tags using regex?

    May 18, 2023 by createIT
    Ultimate GDPR – get user consent logs
    • Dev Tips and Tricks

    Ultimate GDPR – get user consent logs

    May 5, 2023 by createIT
    Backend Developer – how to become one?
    • Technology
    • Trends

    Backend Developer – how to become one?

    May 5, 2023 by createIT
    SEO Checklist for website migration
    • Services

    SEO Checklist for website migration

    April 4, 2023 by createIT
    A game changer for WooCommerce users
    • Our Highlights

    A game changer for WooCommerce users

    March 24, 2023 by createIT
    Write content that sells
    • Trends

    Write content that sells

    March 21, 2023 by createIT
    The differences between a web app and a mobile app
    • Services
    • Technology
    • Trends

    The differences between a web app and a mobile app

    March 7, 2023 by createIT
    Webrooming and showrooming
    • Trends

    Webrooming and showrooming

    February 14, 2023 by createIT
    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

    Support – Tips and Tricks
    All tips in one place, and the database keeps growing. Stay up to date and optimize your work!

    Contact us