urZONE / Deployment Guide

Convert WordPress to Multisite

Turn an existing single WordPress site on your VM into a network that can host many sites from one installation. Follow the steps in order, and use the Copy buttons to send only the commands you need to your terminal.

01 Prepare 02 Convert 03 Manage

Before you begin

Working WordPress

This guide assumes a working WordPress install on Apache, such as the one from the urZONE WordPress guide, with files in /var/www/html, root access, and administrator access to the dashboard. On Nginx, the rewrite rules differ.

Subdirectories or subdomains

Subdirectories give sites addresses like example.com/shop and need no extra DNS. Subdomains give shop.example.com and need a wildcard DNS record (*.example.com) pointing at the VM. Existing sites may be limited to subdomains, so decide before you start.

Apache settings

Multisite needs mod_rewrite and AllowOverride All for the web root. The urZONE WordPress guide sets both up in Steps 02 and 06.

Run with care: Converting to multisite edits core configuration files and adds database tables. It is easy to enable and awkward to undo, so take a VM snapshot and a backup first.

Step 01

Back up files and database

Connect to the VM as root and save a copy of the site files and database. This assumes the database is named wordpress; use your own name if it differs.

Local terminal · SSH
ssh root@YOUR_SERVER_IP
Root terminal · Backup
mkdir -p /root/wp-backup
mariadb-dump wordpress > /root/wp-backup/wordpress-$(date +%F).sql
tar -czf /root/wp-backup/wp-files-$(date +%F).tar.gz -C /var/www/html .
ls -lh /root/wp-backup

Download these files to another machine so a VM failure cannot take your only copy with it.

Step 02

Deactivate all plugins

In the WordPress dashboard, open Plugins, select every plugin, and choose Deactivate. This avoids conflicts during conversion. You will reactivate them afterward.

Also check that your permalinks work and that Settings → General shows the correct site address.

Step 03

Allow multisite

Open wp-config.php and add the line below on its own line above the comment that says That’s all, stop editing!

Root terminal · Open configuration
nano /var/www/html/wp-config.php
wp-config.php · Add this line
define( 'WP_ALLOW_MULTISITE', true );

In nano, press Ctrl+O then Enter to save, and Ctrl+X to exit.

Step 04

Run the Network Setup

Reload the dashboard and open Tools → Network Setup. Choose Sub-domains or Sub-directories, set the network title and administrator email, and select Install.

WordPress then shows two code blocks made for your site, one for wp-config.php and one for .htaccess. Keep that page open and copy from it in the next steps.

Use your own screen’s code: The examples below show the shape of what WordPress generates, but the Network Setup page contains your real domain and your chosen type. Prefer its values if they differ.

Step 05

Add the network settings

Open wp-config.php again and paste WordPress’s first code block below the WP_ALLOW_MULTISITE line, still above the stop editing comment. Example for a subdirectory network, where example.com is your domain:

wp-config.php · Example network settings
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
define( 'DOMAIN_CURRENT_SITE', 'example.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

For a subdomain network, SUBDOMAIN_INSTALL is true instead.

Step 06

Replace the rewrite rules

Open .htaccess and replace the existing block between # BEGIN WordPress and # END WordPress with WordPress’s second code block. Copy the version that matches your network type.

Root terminal · Open rewrite rules
nano /var/www/html/.htaccess

Sub-directory network

.htaccess · Sub-directories
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [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]

Sub-domain network

.htaccess · Sub-domains
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
Step 07

Log back in and check

Return to the WordPress login page and sign in again. You should now see My Sites → Network Admin in the admin bar. Open this address to reach the network dashboard:

https://example.com/wp-admin/network/

Replace example.com with your domain, and use http if you have not enabled HTTPS.

Root terminal · Apache check
apache2ctl configtest && systemctl reload apache2
Step 08

Add sites and reactivate plugins

In Network Admin → Sites → Add New, create your first extra site by entering its address, title, and administrator email. Then go to Network Admin → Plugins and use Network Activate for plugins every site should have. Plugins that should run on only some sites can be activated from each site’s own dashboard.

Some plugins and themes are not multisite compatible. Test each one after activating it, and enable themes for the network under Network Admin → Themes.

Subdomains only

DNS and HTTPS for sub-domain networks

Add a wildcard DNS record, *.example.com, pointing to the VM’s IP address, and make sure Apache’s default site answers all hostnames. A standard single-site certificate does not cover new subdomains. Wildcard certificates from Let’s Encrypt require DNS validation, so follow Certbot’s instructions for your DNS provider.

If needed

Roll back to a single site

If conversion fails, restore the snapshot or the backup from Step 01. To restore the backup, replace the date in each file name, then run the commands. This overwrites the current site and database.

Root terminal · Restore backup
mariadb wordpress < /root/wp-backup/wordpress-YYYY-MM-DD.sql
tar -xzf /root/wp-backup/wp-files-YYYY-MM-DD.tar.gz -C /var/www/html
chown -R www-data:www-data /var/www/html
systemctl reload apache2

Before running: Restoring replaces everything changed since the backup, including posts and uploads. Check the file names first with ls /root/wp-backup.

Keep building

Keep WordPress, themes, and plugins updated from the Network Admin, limit Super Admin access to people who need it, and back up the database and wp-content regularly. Every site on the network shares one database and one set of plugins, so test updates before applying them.

References: Create a network · Before you create a network · Multisite administration