Word Press Multi-Site

Fellow educators, free software hackers, and other community members, I have begun the #LiDA103 course and I am posting this new feed to see if syndication is working and to “declare myself.” Here goes!

I am a math teacher at SF Community College, do contract work as an IT Consultant at Schaefer IT Consulting under my business DBA Haack’s Networking and serve on three educational non-profit Boards: NM Council of Teachers of Mathematics, NM Partnership for Math & Science Education, and Learning Through Horses. In case I was not busy enough, I am working on an Ed.D. in Educational Leadership at UNM, raising a 5/7 year old son/daughter, and spend time working on Free Software haacktivism, system’s administration, and ways to break down traditional educational barriers on the side. Oh yeah, and I love hiking, backpacking, and playing basketball.

I am taking the #LiDA103 course because I have a keen interest in integrating Free Software into my own research practices (and already do), utilizing Free Software for educational offerings such as co-work/co-learn spaces, and fomenting transformational educational change in policy that involves back-middle-front end use of Free Software.

I have already been challenged by the program content. Additionally, I have begun informal discussions with OERu leaders that have challenged me as well. For example, in discussing matters with Dave and Wayne over at the OERu it turned out I found a hole in my intermediate WP knowledge. Namely, because of the scope of my operations in WP, normally small non-profits and simplistic websites (nmctm.org / lthsf.org), I had never needed to set up multi-site functionality. It became apparent, however, in the consultation that this would be essential for a side project of mine. So, I banged it out. Here is what I did:

First, I used an existing self-hosted WP instance. If you do not know how to set up a self-hosted WP instance, consider my tutorial Self Hosted WP. Once you have WP 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 wp-config.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
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]
^(..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. After this, I navigated back to WP and set-up both sites using the new “My Sites” panel at the top (yes, I had done them multiple times before but failed). Once I went in exactly this order/fashion, everything worked and, in fact, I write this educational blog to you now using one of those new multi-sites. In fact, if everything goes okay, since I used an identical virtual host name as my previous non-multi-site virtual host, this post should simply syndicate to #LiDA103 flawlessly. Hope it does and, if it does not, more haacking to come!

[I almost forgot to mention that the Rest API will have trouble with multi-sites if AllowOverride are not set to All. Navigate to /etc/apache2/apache2.conf and set web-root to “All” in the relevant section.]

Leave a Reply

Your email address will not be published. Required fields are marked *