how to create a subdomain in a dedicated apache2 server



I want to create a subdomain I followed this steps :

cd /etc/apache2/sites-available

<VirtualHost *:80>
        DocumentRoot /var/www/testfolder/
<Directory "/var/www/testfolder">
        AuthType Basic
        AuthName "test"
        AuthUserFile /var/www/testfolder/passwords
        Require valid-user test

exit and save

/etc/init.d/apache2 reload

but It’s not working am I missing something ?


In order for this to work, you additionally have to configure DNS resolution for the new hostname If you are just playing with this locally and do not want to create a “real” DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. If you are running the web server on the same machine as the browser, you will want to map to If the browser is on a different machine on your local network, you’ll need to determine the server’s IP address and then on the browser machine, edit /etc/hosts to add the mapping.

On Windows, the file is called C:\windows\system32\drivers\etc\hosts

A sample entry would be (for the browser running on the same machine as the server):

If the server is at, say, the entry would be

EDIT: If the server has a real routable IP address, then if you want the address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server’s real IP instead of Do this on the system where you are running the browser.

Answered By – Jim Garrison

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More