Multiple Project URLs in Windows/Apache

Ever wanted to have your dev WAMP / XAMPP server to run multiple web projects on its own dummy hostnames?  Want your http://localhost/ point to the same document root but still need multiple dummy hostnames such as http://www.project1.local/ or http://www.project1.com.dev/ pointing to different project folders?

Well, the answer is to take advantage of Apache’s VirtualHosts feature and place dummy URLs in your hosts file.  In WinXP, your hosts file is located at the directory path: C:\Windows\System32\drivers\etc\

Note that the ‘hosts’ file has not extension so if you get a Open with dialog choose an appropriate text editor or simply notepad.

Once you have the file opened add a new line in the end like as show below:

        127.0.0.1      http://www.project1.local
        127.0.0.1      project1.local

So, now the first half of it is over.  To check the progress, open a cmd prompt and type “ping project1.local” you should see the ping going to 127.0.0.1.  Also, if you open your browser and point to where apache is running (http://localhost/ or http://localhost:81/ depending upon your setup) you would see the original document root files as expected and as it was working—you could also do: http://www.project1.local or http://project1.local

At this point, both http://localhost/ and http://www.project1.local/ point to the same directory location.  Now, here comes the VirtualHosts trick:

Open your httpd.conf file (C:\wamp\Apache2\conf\httpd.conf on a default WAMP installation) and append the following lines near the end

NameVirtualHost *

<VirtualHost *>
  ServerName localhost
  DocumentRoot "C:/Wamp/www"
</VirtualHost>

<VirtualHost *>
  ServerName project1.local
  DocumentRoot "C:/Wamp/project1"  # Change here
</VirtualHost>

Restart your apache server and thats it.. http://localhost/ will point to your default C:/wamp/www directory files and http://project1.local/ will point to the other different set of project files!

Target Audience: Beginner Apache Administrators, Beginner to Intermediate PHP Developers.
Difficulty level: Easy
Time: 10-15 minutes

Name:

Email:

Location:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?

Submit the word you see below: