Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Ubuntu LAMP site hosted at

I have a directory called john that is accessible via I would like it instead to be accessed via

My site root is /var/www and this directory is at /var/www/john

What do I need to do to make this happen?

share|improve this question
Clarifications, plz: 1) is it ok if both and work? 2) Should any subdirectory automatically be converted into a subdomain or only those you configure? – Bittrance Mar 10 '11 at 18:44
@Bittrance, I would prefer only john.domain work and not domain/john but its not a big deal either way. Also only for ones I configure, although I would also be interested in knowing how to make it auto for every directory. – JD Isaacks Mar 10 '11 at 18:47
Making new dirs become subdomains needs a script, AFAIK. Don't think you can express that in Apache config terms. – Bittrance Mar 10 '11 at 19:05
up vote 9 down vote accepted

Create a new site file at /etc/apache2/sites-available/

Set up the site something like this:

<VirtualHost *:80>
    DocumentRoot /var/www/john
    <Directory /var/www/john/>
        Order allow,deny
        Allow from all

Enable the site with a2ensite

Reload apache to enable the site: service apache2 restart

share|improve this answer
I tried this, - I replaced with my actual site and I restarted apache differently: /etc/init.d/apache2 reload .. I didn't get any errors, but it doesn't seem to be working. Can I be missing something else? or does it take a while to work? Thanks. – JD Isaacks Mar 10 '11 at 19:11
@John: As mentioned in one of the other answers, you'll need to set up DNS to point to the site as well. DNS will take some time, but the Apache part takes effect as soon as you restart the service. – Shane Madden Mar 10 '11 at 19:15
Thanks, I just set the DNS, so I will wait a while and see if it works. :) – JD Isaacks Mar 10 '11 at 19:18
one last thing. http is pointing to /var/www/john but https is pointing to just /var/www any ideas? Thanks. – JD Isaacks Mar 10 '11 at 19:44
@John You'll need to configure an SSL VirtualHost for the SSL listener, you can model it off of the default-ssl file under /etc/apache2/sites-available/. Keep in mind that the certificate will throw a warning if it doesn't match the domain name. – Shane Madden Mar 10 '11 at 19:53

Apart from configuring Apache, don't forget also the DNS part: you will need a record for, pointing to the same IP address points to (if using an A record), or to itself (if using a CNAME record).

share|improve this answer
Thanks, I did what Shane Madden suggested, I also just added the subdomain in the DNS manager at to point to the same IP like you said. It still isn't working, would it take a while before it starts to work? – JD Isaacks Mar 10 '11 at 19:17
Yes, public DNS always have some latency, when you make a modification it will need a while (usually 24-48 hours) to be acknowledged by the whole Internet. Meanwhile, if you want to test it, you can put an entry in the hosts file of any computer to map to the server's IP address, and then test the URL in its browser. – Massimo Mar 10 '11 at 19:35
+1 that worked thanks! :) – JD Isaacks Mar 10 '11 at 19:42

These steps worked for me in Ubuntu 12.04 LTS x86_64:

You need to create a new site file at /etc/apache2/sites-available/

The extension ".conf" is very important, without it, the rest won't work!!

Then set up the site something like this:

<VirtualHost *:80> ServerName DocumentRoot /var/www/john <Directory /var/www/john/> Order allow,deny Allow from all </Directory> </VirtualHost>

Save the changes and enable the site with the command:

sudo a2ensite

Reload apache to enable the site with:

sudo service apache2 reload

Restart apache service:

sudo service apache2 restart

After that, you need to set up DNS to point to the site as well (as a Subdomain), DNS will take some time but in my experience it only takes a few minutes (15).

Hope this helps!! :)

share|improve this answer

you need to create a vhost for your webserver (assuming apache) that has at least the following info

<VirtualHost *:80>
DocumentRoot /var/www/john

this is not a definitive vhost file but is a starting point, it should go in the bottom of your httpd.conf file or wherever your system manages vhosts

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.