jump to navigation

Adding Virtual Hosts to Apache & Wampserver October 16, 2010

Posted by Tournas Dimitrios in Uncategorized.

Being able to develop on my local machine with urls like http://testsite/index.php has been a godsend. Mostly because I am able to take full advantage of the document root. If I were to develop on something like http://localhost/testsite/index.php I would be extremely limited and forced to used relative urls. In this article I’ve listed the steps in order to enable this functionality in a wamp server environment.

This is my method for enabling Virtual Hosts on my wampserver on my own local machine but I don’t see why it wouldn’t work for any old Apache installation. If you have trouble with it, leave me a message in the comments below and I’ll be happy to help.

Step 1: Open your hosts file.

  1. Navigate to your hosts file normally located in \WINDOWS\system32\drivers\etc\hosts
  2. Open the file named hosts (no extension) with notepad.
  3. Add this line to the bottom:        testsite
    This tells your computer that any url with a value of ‘testsite’ should be routed to or more commonly refered to as localhost aka your own machine.
  4. Next, open httpd.conf located in \apache\conf\httpd.conf
    If you installed wamp server this is located at \wamp\bin\apache\apache2.2.6\conf
  5. At the very bottom add these lines:


NameVirtualHost *:80
<VirtualHost *:80>
 DocumentRoot "c:/wamp/www/myfirstsite/"
 ServerName testsite


Restart apache and you should be able to type http://testsite/ into any browser (may need to restart that too) and it will show you the DocumentRoot you just set.

The first line, NameVirtualHost *:80 tells Apache to look out for virtual hosts using its own naming convention. The next couple lines set up a virtual host. You can use as many of these as you want and set up as many sites as you may be developing at one time. Personally, I find this method to be invaluable.. I hope it helps someone else out there.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s