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.
- Step 1 :Change Host File
- Step 2 :Change httpd.conf File
- Step 3 :Change httpd-vhosts.conf File
Let’s go in detail of every step.
Step 1 : Change Host File
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
Step 3 : Change httpd-vhosts.conf File
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.