If you’re a web developer you know how fantastic WampServer is in allowing you to have Apache, MySQL and PHP server locally under Windows. This allows you to test all your websites locally before you upload them into the “real” server.
Now, the problem is that by default if you have two sites (site1 and site2) locally, it’s always a pain having to browse them by using “https://ruifeio.com/site1/index.php” as a URL.
The best way is always to make the URL shorter and for this WampServer allows you to create Virtual Hosts. The general idea of Virtual Hosts is
that you can use something like “http://site1” or “http://site2” instead of having to use the complete URL.
Here’s how you do it:
1. Edit the “hosts” file on your windows system (usually located at c:\WINDOWS\system32\drivers\etc\)
2. Add the following to the end of the hosts file:
127.0.0.1 site1
127.0.0.1 site2
This tells your computer that any url with a value of ‘site1’ or ‘site2’ should be routed to 127.0.0.1 or more commonly refered to as ruifeio.com.
3. Save your changes.
4. Now go to “C:\wamp\bin\apache\Apache2.2.17\conf” and edit file “httpd.conf”
5. Search for “httpd-vhosts.conf”
6. Remove the “#” from the beginning of the line “Include conf/extra/httpd-vhosts.conf”
7. Now go to “C:\wamp\bin\apache\Apache2.2.17\conf\extra” and edit file “httpd-vhosts.conf”
8. Add the following lines to the end of this file:
9. Click on the WampServer icon
10. Select “Restart All Services”
And that’s it! From now on you only have to use “http://site1” and “http://site2” as URLs for your 2 local websites.
Notes:
– These instructions may not work for older versions of WampServer.
– On Windows 7 you will need to edit the “hosts” file running Notepad as Administrator.
Thank for share !
full article.
Great work man 🙂 well done windows 7 everything ok. Exept that in the vhost texts the quotes are not the appropriate ones and the apache can’t start, but when they are replaced with the “normal” everithing works great.
I switched to wampserver as I was having trouble running apache on windows 7 – it would just start and then stop.
Your instructions worked perfectly, thank you!