I’ve been using Linode for a few months to host about a dozen websites and I’ve been very happy with the experience. I have found the documentation at Linode to be clear and concise, especially when it comes to setting up multiple sites using a standard, Ubuntu-based LAMP (Linux, Apache, MySQL, PHP) configuration.
I decided to take one of the sites to the next level and add a subdomain. (An example of a primary domain is davidpodley.com while a subdomain would be the ‘blog’ in blog.davidpodley.com.) Unfortunately, Linode’s library and other documents was less than clear about all of the steps.
My goal here is to explain, step by step, how to add a subdomain to your Linode service. I suppose this could work for any Ubuntu-based LAMP stack, but this may have some Linode-specific information.
**NOTE: My DNS services are managed at Linode, so I’ll assume you have done the same thing yourself.
First, we will tell the server what to do with traffic coming to the address.
- Log into the Members section of Linode (linode.com/members) and find the Linode you want to add a subdomain to. Make a note of the IP Address (you will use this later). If you’re like most users, you will only have one Linode listed.
- Next, open the DNS Manager at Linode by clicking ‘DNS Manager’ at the top. This should take you to a page that has at least one domain listed.
- Select the domain you want to add a subdomain to. This will take you to a screen that lists several options. Mine lists SOA Record, then NS Records, MX Recods, then A/AAAA Records. Under the listed A/AAAA Records, click ‘Add a new A/AAAA Record’. **(UPDATE: I’ve read that one user had a problem getting this to work with an A Record, but was able to get it to work using the CNAME Record. I don’t believe it should matter, but if you’re having problems, you may want to use the CNAME.)**
- You will be taken to a page with a form that says, ‘Add/Edit an A Record’. In the ‘Hostname:’ field, enter the name of your subdomain ‘blog’, ‘shop’, or ‘xyz’ could be examples. In the ‘IP Address:’ field, enter the IP address you made note of in the first step of this document. Click ‘Save’.
- You will be taken back to the previous page. I click ‘Render’ at the bottom. I don’t know that it does anything, but it doesn’t seem to hurt. (***UPDATE*** Since this was written, it seems as though Linode has changed their DNS system. I don’t see the ‘Render’ button any more. Also, the look of the DNS system has changed. The end result should be the same, but you may see something slightly different than what I mention here.)
That wasn’t that difficult, was it? Well, now we get to go into dealing with actually setting up the subdomain on the Apache side.
# cd /etc/apache2/sites-available
If you run the command
You will see the sites you’ve defined so far. You will need to create another site titled xyz.YOURDOMAINNAME.com, where xyz is the subdomain of your choosing. You can do this by either copying an existing, working site definition or by creating a new file. I usually copy an old site using:
# cp example.com xyz.YOURDOMAINNAME.com
Now enter the command
# nano xyz.YOURDOMAINNAME.com
You should see a box with text similar to:
<VirtualHost *:80>ServerAdmin admin@YOURDOMAINNAME.comServerName YOURDOMAINNAME.comServerAlias www.YOURDOMAINNAME.comDocumentRoot /srv/www/YOURDOMAINNAME.com/public_html/ErrorLog /srv/www/YOURDOMAINNAME.com/logs/error.logCustomLog /srv/www/YOURDOMAINNAME.com/logs/access.log combined</VirtualHost>
ServerName xyz.YOURDOMAINNAME.comServerAlias www.xyz.YOURDOMAINNAME.comDocumentRoot /srv/www/YOURDOMAINNAME.com/public_html/xyz/
<VirtualHost *:80>ServerAdmin firstname.lastname@example.orgServerName xyz.YOURDOMAINNAME.comServerAlias www.YOURDOMAINNAME.com (EDITED FOR AN ERROR – USE THE LINE BELOW)
CustomLog /srv/www/YOURDOMAINNAME.com/logs/access.log combined
# mkdir -p /srv/www/yourdomainname.com/public_html/xyz
# a2ensite xyz.yourdomainname.com
# /etc/init.d/apache2 reload
It may take anywhere from an hour or so to a day for the subdomain to propagate through the DNS system. I errantly assumed it would be immediate because DNS was managed by Linode, but it took about an hour for it to respond to my browser.
Help Keep This Site Going
If you found value to this article, please consider donating a dollar or two to help cover the cost of managing this site.
Alternately, if you’re interested in becoming a Linode user, please use this affiliate link before creating a Linode account.