Virtual Hosts in Windows, Linux, Mac for developer

Virtual hosting is a method for hosting multiple domain names on a computer using a single IP address. One widely used application is shared web hosting. Beside this, It is very usefull to developer while developing his site locally or in dedicated server. Let’s me explain –

1. Let i’m developing a site locally, if the project folder name is “myapp”, i need to browse this site by http://localhost/myapp/, i may want to browse my site by

2. I’ve a larger site, developing locally, will have different domains which share login and all domain locate same folder. That is
if anyone logged in –
later he visits
he doesn’t need to login again by verifying the security, how can you test it locally?

3. Let you have a live site already(let, you are re-developing this site on a new dedicated server(lets ip is, so you are browsing your developing site by – But if you want to access your developing site with from your desktop while keeping that the live site accessible to others by

Hence the virtual hosts. There may be some other reasons that i can’t remember at this moment. Here are the ways to how to configure virtual hosts in windows, linux and mac.

Configuring virtual hosts in windows

let you have mydomain folder in your xampp htdocs want to browse your application by, find out hosts file and open it in notepad. Host file location is –

Add the following line bottom of this file

First part is loopback address, second part is the domain name by which domain you want to access that folder. So if you hit on, it will hit on your local server instead to search on internet. Now add this domain name on your httpd configuration file. To do this, open “C:\Program Files\xampp\apache\conf\httpd.conf” file(in xampp, you will find it inside apache/conf in other package), add the following lines at the bottom of this file –

# Use name-based virtual hosting.
NameVirtualHost *:80
<VirtualHost *:80>  
    DocumentRoot "C:/Program Files/xampp/htdocs/mydomain"    
    CustomLog logs/ combined
    ErrorLog logs/    

So for port 80 requests(for https it should be 443), it loads site from mydomain folder. Restart your apache and hit on, see what’s come. Exciting, huh?

Configuring virtual hosts in Linux

In linux, this is little different. Check this here

Configuring virtual hosts in Mac MAMP package

Open hosts file which is in following location
Now add the following line at the bottom of hosts file

Now add the following lines in httpd configuration file(File is located here – “/Applications/MAMP/conf/apache/httpd.conf”

NameVirtualHost *
<VirtualHost *> 
DocumentRoot "/Applications/MAMP/htdocs/mydomain"

This is little more different than previous one, this handle http and https requests. Also one alias is added too. Don’t forget to restart apache to get the changes.

One thought on “Virtual Hosts in Windows, Linux, Mac for developer

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.