Thursday, 21 May 2015

Create Virtual Hosts using WAMP in windows

I want to share that how to create virtual host in wamp server in window environment.
For e.g. we want to create virtual host for project name mage-domain
So we simply type http://localhost/mage-domain/ in browser url

now we will create virtual host for same project. So it will be look like as follows:

http://mage-domain.com



A) Go to C:/Windows/System32/drivers/etc.

You will find the file named "hosts". Open this file in Text Editor.

B) Please add a following text line at the end of the file:


127.0.0.1       localhost  //if exists then dont add

::1             localhost //if exists then dont add

#mage-domain.com is added 

127.0.0.1   mage-domain.com

c) Go to D:\wamp\bin\apache\apache2.4.9\conf

Note: Apache version and Computer drive may be vary in terms of individual.
Open the file named "httpd.conf" in Text Editor not "httpd.conf.build".

d) Search for this pharse "# Virtual hosts". 

Remove # tag before the line "Include conf/extra/httpd-vhosts.conf":

Old:

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
New
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

This will we set our virtual hosts file to Apache.

e) Go to D:\wamp\bin\apache\apache2.4.9\conf\extra

Open the file named "httpd.vhosts.conf".

<VirtualHost *:80>

ServerName mage-domain.com
DocumentRoot D:\wamp\www\php_project
<Directory "D:/wamp/www/php_project/">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Note: ServerName and host name (that name we have added in hosts file) both must be same.


f) Restart your wamp server.