jump to navigation

Setting Up Multiple Virtual Hosts in WAMP April 2, 2011

Posted by Tournas Dimitrios in Zend Framework v1.10.

WAMP, or Windows Apache MySQL PHP  , is probably the most used  server for  PHP developers who uses Windows environment. These are mainly the freelancers who mostly uses laptops as their local development machines. Whatever may be the reason , when you use WAMP , it becomes difficult to manage multiple application installed in same root.

For example while we use WAMP as a development environment, we have different client specific projects residing in different folders in the root and whenever these projects needs to be uploaded in production environment, the absolute paths has to be manually change.

What if we want to have different root folder for each client? Well, this is possible in WAMP using Virtual Hosts. Let us see how to setup the virtual hosts.

First we need to modify two files to create virtual hosts:

  1. hosts file: This file is in the c:\windows\system32\drivers\etc\  folder
  2. httpd.conf file: This is in your Apache install’s ‘conf’ folder – e.g. c:\wamp\Apache2\conf\httpd.conf

The hosts files has entries which maps IP Address to a name. By default the name “localhost” is mapped to IP Address : ”   localhost “
Now what we have to do is to simply add few more entries per client in this file. You may want to use your clients domain name as mapping key :  ”    customerdomain.local
Add as many entries as you want in hosts file. Whenever you enter “customerdomain.local” in your web browser, windows will first look into hosts file and if it gets the corresponding entry, it sends the request to that IP Address (in our case ) . Now we have to change httpd.conf ,  Open the httpd.conf file and search for something like:
DocumentRoot “C:/program files/wamp/www”
Add following code after the ‘DocumentRoot “c:/program files/wamp/www”‘ entry in httpd.conf file.

Save your modifications on the hosts and httpd.conf file and restart your wamp server .

Accessing the resources from your browser can be done with  :
localhost   ,   customerdomain.local  ,   zapas.local

By default wamp is working in a  ” sandbox environment” , for security reasons it can only serve files from it’s root folder .  We can override this restriction through “Directives  ” in the httpd.conf  configuration file . As you see on the last Virtual entry we have included a Directive to allow wamp ( Appache ) to serve documents outside it’s root folder .

On a development environments where many virtualHosts have to implemented , a good practice is to list all the virtualHost’s on a external file  and wamp configure to parse this external file . The Directive for this external file would be :  Include   conf/extra/httpd-vhosts.conf

And now you need to modify the code a bit to match the server name with the one from your ‘hosts’ file and the DocumentRoot with your clients file path



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s