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.
c:\wamp\bin\Apache\Apache.*.*.*\conf\httpd.conf (*.*.* is version of Apache)
LoadModule vhost_alias_module and you will see something 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 the version of Apache)
and add the below code at the bottom
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org 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 :
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 -
<Directory/> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory>
<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.