Setting up virtual Host on Wamp Server is very easy. But first, we should look why it is beneficial to set up the virtual host.

While developing a site most of the developers works on the local server using WAMP/XAMPP server. In this case websites in development are stored in default root ie; c:\wamp\www in WAMP or in htdocs in XAMPP.

So if we are developing a site on the local server then the site can be accessed by localhost/example.com and the pages can be accessed by localhost/example.com/about.php or localhost/example.com/contact.php etc.

But this can be eliminated by using virtual host server and we can access the site as if they are live. for example, if we are developing a WordPress site on the virtual host we need not change the URL in the database when moving the site from local to live server.

Let's start setting up the virtual host on windows.

Step 1:

open c:\wamp\bin\Apache\Apache.*.*.*\conf\httpd.conf (*.*.* is version of Apache)

virtual-host-setup-step-1

Then find LoadModule vhost_alias_module and you will see something like this 

vhost_alias_module modules/mod_vhost_alias.so

Uncomment this by removing #

virtual-host-setup-step-1-a

Next, find Virtual Hosts , just in next line 
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf --> Uncomment this by removing #

virtual-host-setup-step-1-b

Save and move to step 2 :

open c:\wamp\bin\Apache\Apache.*.*.*\conf\extra\httpd-vhosts.conf (*.*.* is the version of Apache)

setting up virtual host on wamp -step 2and add the below code at the bottom 

<VirtualHost *:80>
 ServerAdmin webmaster@example.com
 DocumentRoot c:/wamp/www/www.example.com
 ServerName www.example.com
 ServerAlias www.example.com
 <Directory "/">
   Deny from all
   Allow from 127.0.0.1
 </Directory>
</VirtualHost>

In above code snippets, replace the example.com with your site directory name ie; myproject.com 

Save and move to step 3 :

Open c:\Windows\System32\drivers\etc\hosts

virtual-host-setup-step-3

and add  127.0.0.1       www.example.com

Done.! We have successfully set up the virtual host on wamp. Restart you wamp and access the site directly like example.com or myproject.com

Error Handling -

In case you get any error like Error 403 or wamp icon not turn green, run c:/wamp/bin/apache/apache2.4.9/bin/httpd.exe which will show the error if any.  Most common error is 403 forbidden. 

Steps to Fix 403 Forbidden Errors in Wamp Server -

open c:\wamp\bin\Apache\Apache.*.*.*\conf\httpd.conf and locate -

<Directory/>
 Options FollowSymLinks
 AllowOverride None
 Order deny,allow
 Deny from all
</Directory>

or

<Directory />
 AllowOverride none
 Require all denied
</Directory>

and replace with

<Directory/>
 Options FollowSymLinks
 AllowOverride None
 Order deny,allow
 Allow from all
</Directory>

Restart the Wamp again.