How to create virtual host in WAMP Server

How to create virtual host in WAMP Server

Let’s see brief intro of Virtual hosts.Basically virtual host gives you filling of server on which you deploy your website.By just entering your desire domain name in browser , it will show locally hosted files.Also virtual hosting is used to manage multiple domain on single server.
Below is the step by step guide to create / setup virtual host in WAMP server.

Let’s go in detail of every step.

Step 1 : Change Host File

host file example

First of all go to C:/Windows/System32/drivers/etc directory.Now open hosts file.And at the end of the file add below line as shown in image.

127.0.0.1       www.example.com

Here add your desire site insted of www.example.com and then save file.

Step 2 : Change httpd.conf File

httpd vhosts file example

Now go to C:\wamp\bin\apache\ApacheX.X.XX\conf directory.Here X.X.XX is the version of apache which you have installed.Now in that directory open httpd.conf file , Not httpd.conf.build file .In that file find httpd-vhosts.conf and uncomment that line as shown in above image.This is useful to start functionality of virtual host in wamp.

Step 3 : Change httpd-vhosts.conf File

httpd-vhosts example

Now go to C:\wamp\bin\apache\ApacheX.X.XX\conf\extra directory.In that directory open httpd-vhosts.conf file.And at the end of the file add following code.

##### Directory in which your content is lying
<Directory "E:/Content/example/src/">
	AllowOverride All
	Order Allow,Deny
	Allow from all
	Options Indexes FollowSymLinks Includes ExecCGI
</Directory>
#####  Virtual Host
<VirtualHost *:80>
##### Root Of your website
	DocumentRoot "E:/Content/example/src/"
##### server name should be same as line added by you in hosts file in step 1.
	ServerName www.example.com
##### Error log in "C:\wamp\bin\apache\Apache2.2.21\logs" directory
	ErrorLog "logs/example.log"
</VirtualHost>

You can remove lines starting with ##### from above code.
That’s all.You have created virtual host.Now restart your wamp server.

Keep In mind:

  • Always check your error log if something is not working.
  • Always check green icon of WAMP in tray , whenever you restart your WAMP server.

External Resorces

More Stories
Should You Have a Graph Database in Your Data Warehouse Stack
Should You Have a Graph Database in Your Data Warehouse Stack?