How to make a directory in site root a subdomain?

Create a new site file at /etc/apache2/sites-available/john.mysite.com

Set up the site something like this:

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

Enable the site with a2ensite john.mysite.com

Reload apache to enable the site: service apache2 restart


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


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/john.mysite.com.conf

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

Then set up the site something like this:

<VirtualHost *:80>
    ServerName john.mysite.com
    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 john.mysite.com

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!! :)