Running virtual sites on WAMP
Update: Wordpress ate some of my code on the original post, which is now fixed. Thanks to Josh for pointing it out!
I recently installed WAMP on my Windows laptop and wanted to run multiple virtual sites on it, so I could develop locally as if I was on the live web server.
I searched Google and found lots of tutorials, but none of them worked for me (probably because I’m a newbie at this server stuff!) After lots of trial and error, I discovered a solution.
So, here’s how to create a few new dev sites you can browse on your local computer, as if they were live:
Step 1: Site directories
Add new development site directories to your web root (i.e., inside c:\wamp\www\).
For our example, we’ll add the following 3 directories for our projects:
- devsite1
- devsite2
- devsite3
Step 2: Update Apache’s httpd.conf file
Open the httpd.conf file. (If you’re using WAMP, look for the icon in the task bar, click it, select Apache and then “httpd.conf” to open the file.)
Search for this line:
NameVirtualHost 127.0.0.1
If it doesn’t exist, scroll down and add that line to the bottom of the file.
Step 3: add your site(s) to Apache
Note: I use a .dev extension for my development sites, inspired by the many tutorials I’ve seen around the web.
Now add your new sites to the bottom of the httpd.conf file:
<VirtualHost 127.0.0.1> ServerName devsite1.dev DocumentRoot c:/wamp/www/devsite1 </virtualHost> <VirtualHost 127.0.0.1> ServerName devsite2.dev DocumentRoot c:/wamp/www/devsite2 </virtualHost> <VirtualHost 127.0.0.1> ServerName devsite3.dev DocumentRoot c:/wamp/www/devsite3 </virtualHost>
Step 4: Update your hosts file (Windows)
Your hosts file is most likely located here: C:\WINDOWS\system32\drivers\etc
Open it in your text editor, and find this line:
127.0.0.1 localhost
On the next line, add your dev sites:
127.0.0.1 devsite1.dev 127.0.0.1 devsite2.dev 127.0.0.1 devsite3.dev
That should do it!
Posted by corey brown on February 26th, 2008
Filed in web |
March 13th, 2008 at 2:32 am
Works great! Vista users will need to edit the hosts file by running Notepad in administrator mode. Otherwise you won’t be able to save the changes.