Skip to Content Skip to Menu

Apache : Setting up sub domains on localhost


Recently I've been trying to setup subdomains to run on my localhost. This will come in handy for testing html code before putting a site live. Note I'm running Apache 2.2.11 on Windows XP. The example of a subdomain is http://localhost/mysite accessed as http://mysite.localhost


At the bottom of your httpd.config (for the Apache server) usually found at c:\wamp\bin\apache\apache-<version>\conf use the following lines:

# Pretty important line - got mine working
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot C:/wamp/www/mysite
ServerName mysite.localhost

<VirtualHost *:80>
DocumentRoot C:/wamp/www
ServerName localhost


Running on windows you will need to change the hosts file to reference the subdomain on the correct IP address. This can usually be found at c:\windows\system32\drivers\etc. Example lines here: localhost mysite.localhost

Hopefully this helps someone as it took a good couple of hours of searching before I found the right solution for my application.