Posts Tagged ‘windows’

Setting up virtual hosts in apache on a windows machine

Saturday, February 21st, 2009

Navigate to your apache folder and find the conf folder (for WAMP this is C:\wamp\bin\apache\apache{version number here}\conf\ by default, for xampp this is C:\xampp\apache\conf\ by default)

Next open the httpd.conf file, and search for the line that has Include conf/extra/httpd-vhosts.conf on it. If there is a # before the line, delete it leaving only Include conf/extra/httpd-vhosts.conf. Save the file and exit it
Next, open the folder extra in the conf folder, and open the file httpd-vhosts.conf
You can delete the contents of the file, and replace with the following


	DocumentRoot "C:\wamp\www"
	ServerName localhost
        Options FollowSymLinks
        AllowOverride All

For my example above, I have used the WAMP default document root for the localhost (C:\wamp\www), as it is set by default. You can change the paths to any directory you like, making sure that both match each other. Now you will need to create a custom virtual host. Supposing you want to make the host myhost, so that typing in http://myhost/ brings up a new document root by default, you would add the following to the file after the above code

	DocumentRoot "C:\virtualhosts\myhost"
	ServerName myhost
        Options FollowSymLinks
        AllowOverride All

Note that there are three parts that are different to the first one. The first two differences are the folders (in this case I’ve set them to C:\virtualhosts\myhost). The second difference is the ServerName which is myhost

Now we need to make a final change to our hosts file. The location of the hosts file is dependant of your operating system. A full list of these can be found at

Most windows users will find it in %SystemRoot%\system32\drivers\etc\
Right click the file, and click properties. Make sure that the Read-only checkbox in the attributes is unticked and click ok. Then open the file for editing (using notepad is generally the easiest method)

We will need to add our new myhost to this file to allow the computer to map the name to an ip. Since the IP will be our local ip ( we simply add myhost to the end of the hosts file on a new line (the gap between the ip and the myhost is a tab by the way). Save this file, close, and restart your apache server

You should now be able to go into your browser and type in myhost, and the C:\virtualhosts\myhost folder will run like your normal document root does

If you have any issues in getting this to work, feel free to contact me