Wordpress-Multisite-Inner

What is a WordPress Multisite?

As en experienced WordPress agency, today on the blog we’ll look at how to migrate a WordPress Multisite domain from local to live. Simples!

WordPress has an awesome feature that allows you to create multiple websites, which can all be managed by one WordPress installation. There are two different options when configuring WPMS address configuration. Sub-domains and sub-directories. This blog article will mainly be looking at sub-directories but the same principles could also be applied to sub-domains.

The Issue

I spend a lot of time performing web development with WPMS on a local virtual server and one of the main issues for me is figuring out how to migrate a #WordPress database from local to live. There are a lot of different tables in the database that have to be changed. Along with some PHP.

So, to ease the pain, I have created some Structured Query Language (SQL) Queries that you can use. Once all the WordPress files are on the new site’s server we can begin!

Note

If you’re going to try and migrate, remember to backup any database or PHP you are going to change. You have been warned!

SQL Queries

First of all we need to change the main WPMS tables.

  1. wp_site
  2. wp_sitemeta
  3. wp_blogs

In this example I have the default table prefix. Of course you would change this to your own prefix.

/* WPMS UPDATE */
UPDATE wp_site SET domain = replace(domain, 'localhost', 'new-domain');
UPDATE wp_sitemeta SET meta_value = replace(meta_value, 'http://localhost', 'http://www.new-domain.com') WHERE meta_key = 'siteurl';
UPDATE wp_blogs SET domain = replace(domain, 'localhost', 'new-domain');

 


Next we update the main site WP tables.

This will change the the sitter as well as any reference to the site within your posts.

/* options and posts UPDATE */
UPDATE wp_options SET option_value = replace(option_value, 'http://localhost', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://localhost', 'http://www.new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://localhost', 'http://www.new-domain.com');

 


Finally, we change the other sites. This is basically an alteration of the our previous query, with the prefix of the site number. In this case, 1.

/* repeat for each domain */
UPDATE wp_1_options SET option_value = replace(option_value, 'http://localhost', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_1_posts SET guid = replace(guid, 'http://localhost', 'http://www.new-domain.com');
UPDATE wp_1_posts SET post_content = replace(post_content, 'http://localhost', 'http://www.new-domain.com');

 


That’s it for the SQL. This should have, if done correctly, changed your site’s url to a new domain.

All together now:

/* WPMS UPDATE */
UPDATE wp_site SET domain = replace(domain, 'localhost', 'new-domain');
UPDATE wp_sitemeta SET meta_value = replace(meta_value, 'http://localhost', 'http://www.new-domain.com') WHERE meta_key = 'siteurl';
UPDATE wp_blogs SET domain = replace(domain, 'localhost', 'new-domain');

/* options and posts UPDATE */
UPDATE wp_options SET option_value = replace(option_value, 'http://localhost', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://localhost', 'http://www.new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://localhost', 'http://www.new-domain.com');

/* repeat for each domain */
UPDATE wp_1_options SET option_value = replace(option_value, 'http://localhost', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_1_posts SET guid = replace(guid, 'http://localhost', 'http://www.new-domain.com');
UPDATE wp_1_posts SET post_content = replace(post_content, 'http://localhost', 'http://www.new-domain.com');

 


PHP

The final thing we need to do is change the site’s domain within the wp-config.php file, which is located in the root of your site.

We need to change this:

define('DOMAIN_CURRENT_SITE','localhost');
define('PATH_CURRENT_SITE','/');

To this:

define('DOMAIN_CURRENT_SITE','new-domain');
define('PATH_CURRENT_SITE','/');

Once all of this has been done you should have a WPMS on a different domain.

If you have any digital marketing queries which you’d like answering please get in touch with us. ‘Till next time!

 

We're recognised by
02034321369
Digital Marketing Agency London +Mike Grindy