Setup WordPress Multiple Site Using Subdomains on VIrtualmin
I keep on seeing a few multi-site WordPress installation using a sub directory but a few have a multi-site using a subdomain. Firing up curiosity, I tried installing a one using subdomains instead.
Setup WordPress Multiple Site Using Subdomains on Virtualmin
The very first step is to load up your editor and edit wp-config.php, you need to add this small line of code
1 |
define('MULTISITE', true); |
You need to logout and relogin after doing this change, after relogging, you will get a new menu under tools called “Network Setup”. Make sure that you disable all your plugins before proceeding.
You need to check the permalinks first under settings menu then proceed to to setup the network, since this is a subdomain approach, select subdomain in the network type. WordPress will complain that your DNS is not setup properly, you can literally ignore this if you want to generate the subdomain aliases manually.
Upgrading wp-config.php
To complete the setup on WordPress side, you need to edit your htaccess file and wp-config.php file.
1 2 3 4 5 6 |
define('MULTISITE', true); define('SUBDOMAIN_INSTALL', true); define('DOMAIN_CURRENT_SITE', 'domain.com'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); |
Upgrading .htaccess file
To complete the setup, make sure that this items exist on your .htaccess file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# BEGIN WordPress <IfModule mod_rewrite.c> 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] </IfModule> # END WordPress |
Completing the update on the server
The not so hard way
You need to add a domain alias on your httpd.conf file and add a server alias
1 |
ServerAlias *.domain.com |
This ServerAlias instructs the server to point all subdomains.domain.com to domain.com if they are not setup. Make sure you made a backup with http.conf since this can mess up your domain hosting if done wrongly.
Next step won’t be pretty for some since we are now going to modify our DNS, some people have no control on the DNS or the DNS host won’t allow a wildcard domain. If your host or domain provider won’t allow a wildcard domain, contact them and ask them to set it up for you.
1 |
*.domain.com. IN A 11.22.33.44 |
Just wait for the DNS to reload and viola, you can now add a new site called site1.domain.com without creating a subdomain..
The easy way using Virtualmin
Open up virtualmin and goto Webmin->Server->Bind DNS -> domain.com
Click “Edit Records File” to open up our DNS editor.
1 |
*.domain.com. IN A 11.22.33.44 |
Open up virtualmin and goto Webmin->Server->Apache WebserServer -> domain.com
Open up “Edit Directive” and add the ServerAlias line.
The Totally Easy and Lazy Way.
Virtualmin uses subservers instead of subdomain, the difference is great since Virtualmin’s subservers can have their own set of everything on default. Own email, own https certificate, own FTP, own mail records and other stuff. We are going to leverage this on our benifit.
Goto Virtualmin->Server Options->Website Options.. look for the “Website matches all sub-domains?” and tick “Yes”. This instructs Virtualmin to treat all subdomains as an alias for domain.com, the good thing, Virtualmin will setup the DNS and the httpd.conf for you.