How do i setup subdomains for my droplet?

  • Posted January 21, 2013

Hi, I’ve set up a LAMP server on an Ubuntu VPS, installed webmin, created DNS records in DigitalOcean panel as instructed by the tutorials. Everything works just fine on the main domain name, but at this point I want to make a test subdomain: to lead to /var/www/test/

I’ve been trying for a while now and I don’t know how to do it. Got lost in CNAME records, A records and settting up virtual hosts in webmin.

Does anybody have any pointers or any good tutorial on it? Thanks.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Not sure if this answer has been answered yet, but here’s my solution. I’m using the latest Ubuntu on my droplet with LAMP, etc. <br> <br>1) Under your DNS settings in the Digital Ocean CP, add an “A” record for the sub-domain. The values should be as follows: <br>Hostname --> <br>IP --> Use the droplet’s IP <br>IMPORTANT: Make sure to add the period at the end of the hostname like I’ve done! <br> <br>2) Open your /etc/apache2/sites-available/default file. I’m assuming you already have the VirtualHost setup correctly for the primary domain, etc. For the subdomain, simply add: <br><VirtualHost *:80> <br> ServerName <br> DocumentRoot /var/www/the-folder-of-your-choice <br> CustomLog /var/www/logs/sub-mydomain.log combined <br> ErrorLog /var/www/logs/sub-mydomain.log <br></VirtualHost> <br>Your VirtualHost info may differ a little based on the setup of your choice. Restart Apache and check to see if you sub-domain works. I had to wait a little before the subdomain worked in my browser. <br> <br>Hope this helps!

We need to add a helper section to the DNS manager which will give a brief write-up on how to use DNS. <br> <br>A lot of new customers that aren’t familiar with some of the DNS settings don’t know these things and it would help them out in getting the configs right the first time.

Configure all VirtualHosts explicitly with a ServerName directive inside of the VirtualHost directive that way its more explicit and will be easier for you to troubleshoot.

shivpatelspp suggests we add the new subdomain settings to the file:

“/etc/apache2/sites-available/default file”

if I want to add, let’s say, the subdomain “” , can I add it to the “/etc/apache2/sites-available/” file ? I actually tried that and apache could not restart and I got the error “Syntax error on line 219 of /etc/apache2/apache2.conf” . The error went away when I removed the subdomain settings from “”.

So apparently I cannot have my subdomain in the same conf file as my domain?

Can/should I create a new .conf file for my subdomain or should it be in the 000-default.conf file?

Thank you very much

I have and on the same same machine, but i want to have on other directory. How can I make it possible? <br>

@alvarix: It doesn’t matter. Having a separate config file for each virtualhost is clearer, though.

Question: <br>When setting up a subdomain on LAMP, does each subdomain have its own conf file <br>eg: <br>/etc/apache2/sites-available/ <br>/etc/apache2/sites-available/ <br> <br>or do all the rules go in the same conf file for <br>eg. <br><VirtualHost *:80> <br> ServerName <br> DocumentRoot … <br></VirtualHost > <br><VirtualHost *:80> <br> ServerName <br> DocumentRoot … <br></VirtualHost >

do i need to create another virtual host for my sub domains <br>