Setting up virtual Host on Wamp Server is very easy. But first we should look why it is beneficial to set up virtual host.
While developing a site most of developers works on 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 local server 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 virtual host we need not to change the URL in database when moving the site from local to live server.
Let's start setting up the virtual host on windows.
Step 1 :
c:\wamp\bin\Apache\Apache.*.*.*\conf\httpd.conf (*.*.* is version of Apache)
LoadModule vhost_alias_module and you will see sometihing like this
Uncomment this by removing #
Virtual Hosts , just in next line
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf --> Uncomment this by removing #
Save and move to step 2 :
c:\wamp\bin\Apache\Apache.*.*.*\conf\extra\httpd-vhosts.conf (*.*.* is version of Apache)
and add the below code at the bottom
Deny from all
Allow from 127.0.0.1
In above code snippets, replace the example.com with you site directory name ie; myproject.com
Save and move to step 3 :
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 -
c:\wamp\bin\Apache\Apache.*.*.*\conf\httpd.conf and locate -
Deny from all
Require all denied
and replace with
Allow from all
Restart the Wamp again.