Wordpress - Convert a Multisite WordPress install into a Single site
I've gone through the steps to extract a site from a multisite install to a single instance now:
- Set up a clean copy of WP but don't install it
- Find the site ID
- Copy the files from blogs.dir/ID/files to the new WP uploads folder
- Copy the theme the site uses and any plugins it uses to the appropriate folders in the new wp-content folder
- Take a back up of the multisite database but only the tables for the target site and the users and usermeta tables using MySQL workbench or equivalent
- Restore the backup to a new database and change the table name prefixes so they are all the same eg. 'wp_SITEID_' to 'wp_'
- Using MySQL workbench or query browser tidy up the users and usermeta tables like so:
DELETE FROM wp_usermeta WHERE user_id NOT IN( SELECT distinct(user_id) FROM wp_usermeta where meta_key LIKE 'wp_SITEID_%' );
DELETE FROM wp_users WHERE ID NOT IN( SELECT distinct(user_id) FROM wp_usermeta where meta_key LIKE 'wp_SITEID_%' );
UPDATE wp_usermeta SET meta_key = REPLACE( meta_key, 'wp_SITEID_', 'wp_' ) WHERE meta_key LIKE 'wp_SITEID_%';
UPDATE wp_options SET option_name = REPLACE( option_name, 'wp_SITEID_', 'wp_' ) WHERE option_name LIKE 'wp_SITEID_%';
- Begin the WP install process to create a
wp-config.php
but don't click 'Run the install' - Create a default .htaccess file if permalinks were in use or just visit the permalinks page in wp-admin
- You'll need to update any old URLs in your database next. Ideally use a safe search/replace tool like the one in wp-cli or its general purpose precursor search/replace db by interconnect/it. Specifically replace
blogs.dir/SITE_ID/files
withuploads
, and if you're changing your site URL search foroldsite.com
and replace withnewsite.com
.
A fair bit of effort and you have to be careful with the database edits but that's the only I can see to extract a single site from an existing multisite with all its settings etc... intact.
EDIT:
As spotted by @Jake I forgot to mention the final steps you may need to take eg. search/replace of old URLs. I've updated the list accordingly.
It is possible to remove the multisite install without reinstall a new blog. Follow steps.
- Create a backup, database dump and file backup of wp-content
- Set constant
WP_ALLOW_MULTISITE
in your wp-config.php toFALSE
Remove or comment MU settings in
wp-config.php
, like this:/** define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); $base = '/wordpress/'; define( 'DOMAIN_CURRENT_SITE', 'localhost' ); define( 'PATH_CURRENT_SITE', '/wordpress/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); */
Remove the MU settings from
.htaccess
, like the source below:# BEGIN WordPress RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] # uploaded files RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] # END WordPress
Create the permalinks new, in the backend
wp-admin/options-permalink.php
and maybe copy the result in.htaccess
, if is not possible for WP, rights for write on this file.Remove un-usefull entries in table
users
; use the follow sql statement in a tool, like phpMyAdmin or Adminer`ALTER TABLE `wp_users` DROP `spam`, DROP `deleted`;`
The follow tables can be dropped:
- wp_blogs
- wp_blog_versions
- wp_registration_log
- wp_signups
- wp_site
- wp_sitemeta
- wp_sitecategories (only, if exist)
(change
wp_
to your database prefix)Now you have only the last tables of other blogs of the network. If you will use it also this content, then export this before via WordPress export as XML and import now in the clean single install.