2008.06.15

Wamp ServerBeing 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.

  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:
    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.
  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:

  6. 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.

Get my RSS Feed!

Comments

works on (7.24.2008 11:33 am) says

This is exactly what I needed!  Thanks!

 

Rajeev Kamal on (7.31.2008 8:14 am) says

GR8 , i killed almost one day to see, how i can make my multiple joomla installation work on same machine as i will use no-ip.com for this. Now i will need to disable my default localhost so that no one alter as the phpmyadmin options are still available from internet.

 

Rajeev Kamal on (7.31.2008 8:23 am) says

can you help me further.
after creating the virtual hosts i want to be able to run my multiple site with the no-ip.com free service. can you guide how to go ahead with this.

 

michael on (12.15.2008 6:48 pm) says

how can my site may be viewed worldwide?

 

Richard Scrivener on (4.5.2009 1:40 pm) says

Mike, 
this is a wonderfully simple and straight forward explanation that WORKS!! You've save me a LOT of time. Thanks

 

Richard Knop on (5.12.2009 8:36 pm) says

Thanks very much for this post.

This is what I needed to be more productive, editing the httpd.conf file to change the document root was becoming very frustrating.

 

Steve on (8.22.2009 3:53 am) says

Did not work for me, rats!

I'm new to this. I installed Wamp, but its in the c:\wamp directory (win xp,sp3)should I have put it elsewhere?
Wamp runs fine, php and MySQL all seem to work, but no dice on the http://testsite/ in my browsers (after restarting both IE8 and FireFox).

Any insight would be greatly appreciated, I'd love to start working in php like this.

 

PixelMaker on (9.8.2009 7:54 pm) says

Hi, 

I am facing the same problem. If I browse http://mysite.local/ it is giving me WAMP index page.

Please help me, if you know what the problem could be. 

Thanks in advance.
PixelMaker.

 

Mike on (9.8.2009 8:05 pm) says

@PixelMaker

Have you restarted apache? Have you named your virtualhost mysite.local ?

 

murraybiscuit on (9.9.2009 3:31 pm) says

I normally set up a subdomain on localhost with a corresponding vhost. that way there's no conflicts. for example: client.localhost/dir vs client.domain/dir.
my database scripts look for "test" or "localhost" or "127.0.0.1" in the url string and automatically set a live or test environment accordingly. that way I don't need to change config files every time I test locally and then upload remotely. i've tried xampp but it's just ugly and bloated compared to wamp. why would I need a mailserver in my local environment when i can just set my smtp in php.ini? the automated scripts on the tray icon are great. much better than xampp. unfortunately you also need to set up an apache alias if you're going to be testing on a lan pc via lan ip address or vbox.

 

murraybiscuit on (9.9.2009 3:33 pm) says

oh yeah, and for that reason, i never use absolute url's. that's asking for trouble :)

 

Jon on (9.16.2009 4:25 am) says

Hi, this is a great tutorial, I could now use testsite to point to my website folder but I can no longer use localhost. 
I found another tutorial with better result:
http://abeautifulsite.net/notebook/79

hope that help someone 

 

rahul on (10.10.2009 4:40 am) says

thanks it was invaluable for me as-well ....thanks 

 

Muhammad Umair on (11.14.2009 10:23 am) says

Also you will need to uncomment this line in your httpd.conf

Include conf/extra/httpd-vhosts.conf

In order to get rid of virtual host pointing to the server default root.

Thank

 

mahrizal on (12.7.2009 5:38 pm) says

great..!
thanks..

 

John on (2.20.2010 2:42 pm) says

Hi there :)

Thanks for this simple method, it helped me a lot :)
BUT, I have a simpler method :) Instead of editing the http.conf, if you place a config file in the alias folder located in the root of your wamp install, it get interpreted as well due to the following line:
  Include "c:/wamp/alias/*"

So all you have to do is place your VHost in a .conf file in there, restart Apache and you are set to go :)

 
* Name
* Email (Will not be displayed)
Website