Wednesday 22 May 2013

Create Multiple Virtual Hosts in WampServer

The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single machine. Today we are going to discuss on how to create multiple virtual hosts in Wamp (Windows, Apache, MySql, PHP) Server. I am hoping that you already have WampServer installed in your machine, if not then you can easily install it from http://www.wampserver.com/en/

Key Files:

hosts (C:\Windows\System32\Drivers\etc)
httpd.conf (C:\wamp\bin\apache\Apache2.2.21\conf)
httpd-vhosts(C:\wamp\bin\apache\Apache2.2.21\conf\extra)

(Note: I am considering that you have installed wamp on C:/ drive)

» Step 1: Go to path C:\wamp\bin\apache\Apache2.2.21\conf and open configuration file http.conf search for the "Virtual Hosts" and uncomment the line "Include conf/extra/httpd-vhosts.conf"


» Step 2: Go to path C:\wamp\bin\apache\Apache2.2.21\conf\extra and open file "httpd-vhosts"


» Step 3: Add the following lines to the very bottom of the file


» For localhost

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot 'C:\wamp\www'
</VirtualHost>

» For site1

<VirtualHost *:80>
  ServerName mysite1.example.com
  DocumentRoot C:\wamp\www\mysite1
  SetEnv APPLICATION_ENV "development"
  <Directory C:\wamp\www\mysite1>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

» For site2

<VirtualHost *:80>
  ServerName mysite2.example.com
  DocumentRoot C:\wamp\www\mysite2
  SetEnv APPLICATION_ENV "development"
  <Directory C:\wamp\www\mysite2>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

» Step 4: Uncomment the line "NameVirtualHost *:80" if its not already uncommented


» Step 5: Now go to "C:\Windows\System32\Drivers\etc" and open "hosts" file. The hosts files has entries which maps IP Address to a name. By default the name “localhost” is mapped to 127.0.0.1 IP Address.

127.0.0.1     localhost

» Step 6: 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.

127.0.0.1     mysite1.example.com

127.0.0.1     mysite2.example.com

Add as many entries as you want in hosts file. Whenever you enter “mysite1.example.com” or "mysite2.example.com" 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.

» Step 7: Finally check for the read-write permission of project folder and restart the Apache.

Hope this help you.

Thanks. Have a great day!!

No comments:

Post a Comment