Being able to develop on my local machine with urls like
htto://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.
- Navigate to your hosts file normally located in \WINDOWS\system32\drivers\etc\hosts
- Open the file named hosts (no extension) with notepad.
- Add this line to the bottom:
127.0.0.1 testsite
This tells your computer that any url with a value of 'testsite' should be routed to 127.0.0.1 or more commonly refered to as localhost aka your own machine. - 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 - At the very bottom add these lines:
- 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.



Comments
works on (7.24.2008 7:33 am) says
Rajeev Kamal on (7.31.2008 4:14 am) says
Rajeev Kamal on (7.31.2008 4:23 am) says
michael on (12.15.2008 1:48 pm) says
Richard Scrivener on (4.5.2009 9:40 am) says
Richard Knop on (5.12.2009 4:36 pm) says
Steve on (8.21.2009 11:53 pm) says
PixelMaker on (9.8.2009 3:54 pm) says
Mike on (9.8.2009 4:05 pm) says
murraybiscuit on (9.9.2009 11:31 am) says
murraybiscuit on (9.9.2009 11:33 am) says
Jon on (9.16.2009 12:25 am) says
rahul on (10.10.2009 12:40 am) says
Muhammad Umair on (11.14.2009 5:23 am) says
mahrizal on (12.7.2009 12:38 pm) says
John on (2.20.2010 9:42 am) says
Tom on (5.25.2010 8:49 pm) says
Tim on (8.26.2010 2:52 pm) says
Adam on (11.3.2010 3:05 pm) says
René Esteves on (11.4.2010 9:38 am) says
Tirthesh Trivedi on (12.13.2010 4:57 am) says
Troy on (1.9.2011 6:42 pm) says
Saeed Neamati on (3.31.2011 5:01 am) says