Posted by chantra on January 26th, 2016
Since wordpress 3.0, it is possible to create a network or site by using the multisite feature. It allows to manage multiple wordpress websites from a single installation. Plugins, themes get installed and maintained in one place, and the individual sites can activate them.
While multisite has its benefits, in my case, I wanted to return to a good old standalone install. I had a plan a long time ago to move multiple websites from drupal onto wordpress, but never got to it. Finally, I much prefer to handle the upgrade of 1 site on it own rather than upgrading all at the same time. While wordpress does a good job at making maintenance easy, I have been bitten a few time in the past by upgrades going bad.
Finally, one should also read WordPress: Create A Network before going head down in setting it up.
Moving off a multisite install is not that straightforward, some of the resource will end up in different places, permalinks need to be fixed and some files need to be moved around.
Before doing anything, make a backup of your site and try to run this tutorial in a VM or dev environment as you may need to adjust a few steps to fit your setup.
Also, to be noted, you should not run this on a live website as this will migration will cause downtime.
This worked for me, but the migration is rather manual and your mileage may vary. Please follow this steps with caution!
Finding your site ID
Now that you have a backup, you will need to find which site ID you are migrating. You can get this from visiting http://example.com/wp-admin/network and find the site you are migrating off.
In this example, I was moving site ID 2.
Exporting your DB
The database table you will want to export may vary depending on the plugins you have installed and used. Here, assuming your site had ID 2 and your db table_prefix was set to wp_, you will want to dump ALL tables starting with wp_2_ along with wp_usermeta and wp_users, as they will contain the users from the multisite.
Here is a 1-liner that may help to get all the required data out assuming:
- DB name: mywordpressdb
- DB table prefix: wp_
- Site ID: 2
mysqldump -u root -p mywordpressdb $(mysql -u root -p mywordpressdb -N -s -e 'show tables;' | grep '^wp_2_') > mywordpressdb.sql
Fixing the DB
Now that we have the relevant tables, it is time to fix the content of the DB. sed is your friend here:
sed -i 's#wp-content/blogs.dir/2/files#wp-content/uploads#g' mywordpressdb.sql # Fix uploaded file locations sed -i 's#wp_2_#wp_#g' mywordpressdb.sql # fix table names sed -i 's#/files/#/wp-content/uploads/#g' mywordpressdb.sql # fix file upload permalinks
At this stage, you should have a database backup that should allow you to restore your wordpress site in standalone mode.
Assuming your wordpress install is in /var/www/wordpress, running the following command should copy the files that were uploaded while using a multisite set up to a standalone setup:
rsync -avz /var/www/wordpress/wp-content/blogs.dir/2/files/ /var/www/wordpress/wp-content/uploads/ rm -rf /var/www/wordpress/wp-content/blogs.dir/2/files
Importing standalone setup DB
The backup we made earlier should contain all the data we need, but to be on the safe side, we will let the wordpress installer bootstrap a new DB and then re-import the data.
Bootstrapping the DB
At this stage, I assume you have a brand new DB called mywordpressdb. To force the wordpress installer to run, we will move wp-config.php in another location and we will copy it back later.
Accessing http://www.example.com should now trigger the wordpress installer. Go through the install steps to setup the database.
To restore the DB from our backup, we will use the mysql CLI:
mysql -u root -p mywordpressdb < mywordpressdb.sql
Fixing the config
We now need to fix the wp-config.php file by removing references to multisite config. Below is an example of the constants that need to be removed from wp-config:
--- wordpress.old/wp-config.php 2016-01-25 17:07:24.437572380 -0500 +++ wordpress/wp-config.php 2016-01-25 23:44:56.432183250 -0500 @@ -119,15 +121,6 @@ * in their development environments. */ define('WP_DEBUG', false); -define('WP_ALLOW_MULTISITE', true); - -define( 'MULTISITE', true ); -define( 'SUBDOMAIN_INSTALL', true ); -$base = '/'; -define( 'DOMAIN_CURRENT_SITE', 'debuntu.org' ); -define( 'PATH_CURRENT_SITE', '/' ); -define( 'SITE_ID_CURRENT_SITE', 1 ); -define( 'BLOG_ID_CURRENT_SITE', 1 ); /* That's all, stop editing! Happy blogging. */
Finally, we need to copy wp-config.php back to /var/www/wordpress/