It is possible to set up a WordPress Multisite with sub-domains on a shared hosting environment while not using the root domain. It took me some time to figure this out so I thought I document it mainly for my own records.
My hosting is like this:
- Shared hosting with cPanel control panel
- Maximum of 25 domains (Addon domains) and unlimited subdomains
- Root domain: myholding.com
- Addon domain: mycompany.com
The goal is to set up a WordPress Multisite with a couple of subdomain sites for each company division such as div1.mycompany.com, div2.mycompany.com, etc.
I use TransIP as the registrar for all my domain names and set the DNS records using their control panel. Every domain has a wildcard DNS record as default. Because of the shared hosting myholding.com and mycompany.com share the same IP address.
Without any additional setup in cPanel any subdomain URL as for instance http://something.mycompany.com will take the browser to my holding.com. This is regardless of whether WordPress Multisite is installed and enabled or not. In effect divi1.mycompany.com will go to myholding.com as well. So WordPress does not even get a chance at responding to the required subdomain URL.
The solution is to create a subdomain in cPanel with a twist.
By default cPanel creates a directory with the same name as the subdomain in the root of that domain. The trick is to set the document root for the subdomain to the root of the (Addon)domain. An example:
- the web root is public_html
- the (Addon)domain is mycompany.com
- the subdomain to create is div1
- then the document root should be: public_html/mycompany.com (and not public_html/mycompany.com/div1)
The downside is that you need to create a subdomain manually for each (subdomain) site you want to add to your WordPress Multisite install. Therefor you can not allow users to create their own sites.
Finally you can create a new site in WordPress and all will be fine.