Migrating a wordpress multisite to a single install
Recently I just needed to decouple several wordpress sites to make them separate wordpress installations, and oh yes it was a pain, doable thing but a pain non the less. If you’re in the same situation and money is not a problem save yourself some time and get this plugin WP Migrate DB Pro it does the job with a few clicks, but if you’re like me and enjoy this kind of quests, then follow along.
One approach to solve the problem is to export everything within wordpress via Tools > Export but this will not save plugin or theme configurations, that’s why the best (yet the riskier) way to do it is to move the database tables to a new wordpress installation.
What we we’ll do is:
- Move the multisite wordpress database tables to a new database.
- Create a new wordpress installation using the database from step 1.
- Search and replace old filesystem and domain references in the wordpress database.
- Move the uploads, plugins and themes folders to our new installation.
- Remove unneeded metadata by running some sql queries in our database.
Let’s begin
First you need to get the ID of the wordpress site in the multisite network,
each subsite has it’s own ID, to find it head to the network admin panel and
then go to sites and click the site you want to decouple from the multisite
network. The ID will appear in the browser’s navigation bar, will be something
like /wp-admin/network/site-info.php?id=8
, in my case the ID it’s 8
.
With that information we’ll make a SQL dump of the wordpress database tables
containing such ID, so select all the tables beginning with wp_8_
(in your case
use your ID) + these tables: wp_users
, wp_usermeta
, theoretically you can
use this command to generate a list of such tables:
$ mysql [dbname] -u [username] -p[password] -NB -e 'show tables like "wp\_8\_%"'
Now generate the dump file:
$ mysqldump -u [user] -p[password] [dbname] [table1] [table2] ... > mytables.sql
Once you have your .sql
dump file, then open up a text editor and search &
replace wp_8_
for wp_
, in Vim you can do this via :%s/wp_8_/wp_/g
, don’t
worry if you see stuff from other multisites, that will be gone by the end.
Now just import that file in to a new empty database, once imported just install a new fresh wordpress in your web server’s public folder and follow the wordpress installer pointing it to your restored database, don’t need to login, we’re not finish yet.
The next thing is to download the Search Replace DB script and place it in the
root of your wordpress installation (this is the same directory where your
wp-settings.php
file is) then navigate to this folder in your wordpress site,
usually the URL is like http://yourwordpres.com/Search-Replace-DB/
.
Now, if you have changed your wordpress site location (path to the wordpress
installation in the file system) then in the Search box we will write the
absolute path to your old site’s public folder,
i.e /home/myuser/web/mywordpress/public_html
and in the Replace box type in the
new path /home/otheruser/web/newwordpress/public_html
click Dry run first to
check what will be replaced, when you want to perform the real substitution
click the Live run button.
If you have changed your wordpress domain then this is a good moment to also search & replace that, look for the old domain and replace it with the new domain.
Now it is time to copy your themes, plugins and uploads. In a multisite wordpress
installation the wp-content/uploads/sites/8/
is the folder you want to copy to
wp-content/uploads/
for your new wordpress. Themes and plugins just map to the
same directory structure so just copy those folders and put them in the same
location (wp-content/plugins/
and wp-content/themes
).
If you move the files to another server then be sure your permissions are correct, you can fix them with the following commands if needed:
$ chown -R newuser:newuser wp-content/ # Replace "newuser" with your site user
$ find wp-content/ -type d -exec chmod 755 {} +
$ find wp-content/ -type f -exec chmod 644 {} +
Finally, to end this post, run these sql queries that will remove unneeded metadata from the other wordpress multisites, you don’t need to run them but if you want a cleaner database you should do it.
Congratulations, you have moved a wordpress site in multisite mode to a single wordpress installation!