Setting Virtualhost Using XAMPP In localhost

Posted by & filed under APACHE SERVER, PHP.

Everyone like to host their site in the name they wanted to host, but most of time it is not possible because someone already bought that domain and hosted their sites. You can make your dream to come alive by setting virtual host in your local system, where you can host your site even in the name of google.com. It much easier and very interseting too setup this on your localhost and see the output.

 

 

Setting Virtualhost Using Xampp In Localhost

Setting Virtualhost Using Xampp In Localhost

To setup a Virtualhost in local, all you need to do is edit the following two server configuration files (hosts.file, httpd-vhosts.conf) in the following location if your are Windows 7 user.

C:\Windows\System32\drivers\etc\hosts.file

C:\xampp\apache\conf\extra\httpd-vhosts.conf

Step 1:

Find hosts.file in the following location (C:\Windows\System32\drivers\etc\hosts.file), then right click on it and open with administrator privilage.

Now add following line at the end of the file.

127.0.0.1               google.com

Now when we type google.com in the browser address bar  by default it points to its localhost. What we had done so far is, we added new domain name to our host file, by default it points to localhost until we espically specify specific directory for that domain name in the httpd-vhosts.conf file.

Here is flow chart what happens when we enter any domain name in our browser address bar.

what happens when enter domain name in browser address bar

Step 2:

Now find the httpd-vhosts.conf in the following location (C:\xampp\apache\conf\extra\httpd-vhosts.conf),  then right click on it and open with administrator privilage.

Now add the following script at the end of the file.

<VirtualHost *>
    DocumentRoot "D:\google"
    ServerName google.com
  <Directory "D:\google">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Note : please restart our local apache server, only after restart chages we made in the httpd-vhosts.conf will take effect.

what we had done now is mapping the domain, that we added in the host file with the directory in our local system. Here I had mapped google.com with the google directory in the D:\ drive. Now when we enter google.com in the browser address bar the files in the D:\ drive google directory will be displayed.

Note: See in the demo page screen instead displaying google home, it displays the local site I had hosted in my D:\ drive.

where

DocumentRoot (‘D:\google’) — Specifies root folder

ServerName — google.com

Now when type google.com in the browser address bar, first of all server looks for the file in the DocumentRoot (‘D:\google’) folder, then it finds requested file that root folder, then it displays output files in the browser.

 .

Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts

If you want any of my script need to be customized according to your business requirement,

Please feel free to contact me [at] muni2explore[at]gmail.com

Note: But it will be charged based on your customization requirement

Get Updates, Scripts & Other Useful Resources to your Email

Join 10,000+ Happy Subscribers on feedburner. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

Get Instant Script Download Access!