Setting Up WordPress Multisite for Site Networks
WordPress Multisite (WPMS) allows managing multiple sites from one WordPress installation with unified database, shared code, and centralized plugin/theme management. This isn't "multiple sites on one server"—it's one WordPress with shared infrastructure. Suitable for media networks, multiregional projects, WordPress SaaS platforms, educational portals. Basic network setup takes 1–2 days; production setup with data isolation and custom plugins takes from 5 days.
Enabling Multisite
Multisite is activated by adding a constant to wp-config.php before setup:
define('WP_ALLOW_MULTISITE', true);
After navigating to Tools → Network Setup, choose addressing type:
-
Subdomains (
site1.example.com,site2.example.com) — requires wildcard DNS and SSL -
Subdirectories (
example.com/site1,example.com/site2) — simpler setup
WordPress generates code for wp-config.php and .htaccess (or nginx.conf). Example for nginx with subdomains:
server {
listen 443 ssl;
server_name *.example.com example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Wildcard SSL for *.example.com—via Let's Encrypt with DNS-01 challenge:
certbot certonly --manual --preferred-challenges dns \
-d example.com -d '*.example.com'
Database Table Structure
Multisite creates prefixed tables for each subsite. Main site uses wp_posts, second uses wp_2_posts, third uses wp_3_posts:
wp_blogs -- site registry
wp_sitemeta -- network metadata
wp_users -- shared users (one registry)
wp_usermeta -- roles stored per-site
-- First site tables
wp_posts, wp_postmeta, wp_options...
-- Second site tables
wp_2_posts, wp_2_postmeta, wp_2_options...
Users are shared, but roles are different for each subsite. User can be editor on site2 and subscriber on site3.
Programmatic Subsite Creation
$blog_id = wpmu_create_blog(
'newsite.example.com',
'/',
'New Site',
get_current_user_id(),
['public' => 1],
1
);
if (is_wp_error($blog_id)) {
error_log('Site creation error: ' . $blog_id->get_error_message());
return;
}
switch_to_blog($blog_id);
update_option('blogdescription', 'New site description');
restore_current_blog();
Custom Domain for Subsite
Domain mapping—attaching third-party domain (client-site.ru) to a Multisite subsite. Native with WordPress 4.5+:
// In wp-config.php
define('COOKIE_DOMAIN', '');
// Via WP CLI
wp --url=site2.example.com option update siteurl 'https://client-site.ru'
wp --url=site2.example.com option update home 'https://client-site.ru'
Add nginx:
server {
listen 443 ssl;
server_name client-site.ru www.client-site.ru;
root /var/www/html;
# same location blocks as main server
}
Network Plugins and Themes
Plugin activated at network level works on all subsites. Plugin activated on specific subsite works only there.
if (is_multisite()) {
$network_sites = get_sites(['number' => 100]);
foreach ($network_sites as $site) {
switch_to_blog($site->blog_id);
// operation for each site
restore_current_blog();
}
}
Content Isolation Between Subsites
Media files are isolated by default: wp-content/uploads/sites/2/, wp-content/uploads/sites/3/. This is secure but complicates resource sharing.
For shared media library—use "Network Media Library" plugin or custom solution.
Scaling and Limitations
Multisite works well up to 50–100 active subsites on one server. Beyond that, degradation starts due to wp_options table and global cache. Signs: slow switch_to_blog, long REST API response.
Solutions: Redis Object Cache with proper key segregation per blog_id, horizontal scaling via Varnish, separate databases per subsite (via HyperDB).
Typical timelines: basic setup of 3–5 subsites—2–3 days. Setup with domain mapping, SSL, network plugins, custom registrar—5–8 days.







