A client on ListingDock asked me to write this tutorial for them. I haven’t posted anything related to Virtualmin in a while. I haven’t had the time. A big thank goes to dap7 for financing this tutorial. So let’s see how to add a sub-domain in Virtualmin.
Before you add a sub-domain in Virtualmin, you need to create it within the domain’s DNS. In this case, DNS was managed by DigitalOcean. Refer to my Adding a Sub Domain with DigialOcean DNS tutorial if you haven’t done this already.
Once you have the sub domain pointing to your droplet, you can move on to Virtualmin part of sub domain creations…
Adding a Sub-domain in Virtualmin
Adding a sub-domain is similar to adding a new domain to your Virtualmin. But instead of creating a new server, you should create a sub-server for your sub-domain. Although creating a top-level server will also work, going with sub-server help you organize your server. So let’s create a sub-server.
Login to Virtualmin with your root password and select the domain you’re adding the sub-domain from left sidebar. You don’t have to worry about that if you only have one domain on your server. It will be selected by default.
Under the domain name drop-down, you’ll find a link with the text Create Virtual Server. Click it and you’ll be taken to a page where you can create a new server. Top-level server will be selected as the server type, click Sub-server from the top menu to change it to sub-server.
New sub-server will be created within few seconds. Once it’s done, you’ll be given a link to view details of the server you just created on the bottom of the page.
Where to upload website files?
On the page that contain your new server details, you can see admin username for the sub-domain, which will be same as the root domain. And you’ll see home directory for the sub-domain, which will be in following format.
If you go to this directory with a FTP client, you’ll see a directory named public_html inside it. This is where you should upload your website files. Meaning the web-root for your sub-domain will look like this,
And remember to use your Administrative Username to upload files. Uploading as root will cause permission errors on your website.
You can find MySQL database and password for the server by clicking Edit Databases from the left sidebar. Your sub-domain should be configured properly now. You can now connect to your server with FTP client and upload your website.