User Tools

Site Tools


computing:wpmultisite

  • wpmultisite
  • Jonathan Haack
  • Haack's Networking
  • netcmnd@jonathanhaack.com

A tutorial for setting up Word Press multisite


First, set up a self-hosted WP instance. If you do not know how to set up a self-hosted WP instance, consider my tutorial Self Hosted WP. Before beginning this tutorial, you should complete Apache Survival for a proper LAMP/TLS setup and then Self-Hosted WP. Once you have LAMP, TLS, and a Word Press instance up and running, set up multi-site as follows (adapted and simplified from wpbeginner.com):

sudo nano /var/www/site1.com/public_html/wp-config.php

Then, add the following lines before the end of the .php file.

/* Multisite */
define('WP_ALLOW_MULTISITE', true);

Once that is done, go to your site1.com/admin and navigate to Tools and select Sub-domains and click Install. Once that is done, edit your wp-config.php file again:

sudo nano /var/www/site1.com/public_html/wp-config.php

Add the following just below the line you added above:

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'haacksnetworking.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Once this is done, edit your .htaccess file as follows (make sure you understand all of this!):

sudo nano /var/www/site1.com/public_html/.htaccess

It should look something like this. Start with a clean .htaccess if migrating, and add your other rules afterwards.

RewriteEngine On
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]
Options -Indexes

Thirdly, you should already have TLS with a LAMP (or FEMP) stack and if you do not know how, consult my tutorial Apache Survival. Once you have the concept of virtual hosts down, you are ready to go. So, let’s say you have followed that tutorial and set up site1.com and site2.com appropriately. In that case, begin by setting up another virtual host for the desired subdomain for site1.com. (I am assuming that you have Wildcard DNS set up for the primary domain, and for the desired subdomains – if you do not know how to do this, set up an account at afraid.org, point your name servers there, and read-up.)

sudo openssl req -x509 -nodes -days 7305 -newkey rsa:2048 -keyout /etc/ssl/private/subdomain.site1.key -out /etc/ssl/certs/subdomain.site1.crt
sudo cp /etc/apache2/sites-available/site1.com.conf /etc/apache2/sites-available/subdomain.site1.com.conf
sudo nano /etc/apache2/sites-available/subdomain.site1.com.conf
sudo cp /etc/apache2/sites-available/site1.com-ssl.conf /etc/apache2/sites-available/subdomain.site1.com-ssl.conf
sudo nano /etc/apache2/sites-available/subdomain.site1.com-ssl.conf
sudo a2ensite subdomain.site1.com.conf
sudo a2ensite subdomain.site1.com-ssl.conf

Okay, now that your self-signed cert and virtual host for the new subdomain are set up, it is now time to set up a formal CA with Let’s Encrypt. This was the primary place I was confused. After looking at Firefox barf at my certificate and re-direct to other sites on my VPS, I finally determined that I needed to add a domain to the certbot command somehow. So, I took a shot and guessed that it might accept a second -d flag. It did, and here is what I executed:

sudo certbot --authenticator standalone --installer apache //-d site1.com -d subdomain1.site1.com -d subdomain2.site1.com// --pre-hook "systemctl stop apache2" --post-hook "systemctl start apache2"

You must “Expand” the subdomains for as many as you have 1, 2, 3 … etc., and that's what the additional ``d`` flags do. After this, navigate back to WP and set-up both sites using the new “My Sites” panel at the top.

oemb1905 2019/12/30 02:16

computing/wpmultisite.txt · Last modified: 2019/12/29 19:18 by oemb1905