Set up multiple virtual hosts on XAMPP for windows

Sep 17, 2013, by admin

Hi all today we are going to see how to Set up multiple virtual hosts on XAMPP for windows

You just have to update the following files:

X:xamppapacheconfextrahttpd-vhosts.conf

First of all,  uncomment the following line to enable name based virtual host on your server’s port 80:

NameVirtualHost *:80

Then you can start adding your virtual hosts. The following listing is just a sample, I usually do.I am assuming ,we create a project which should be accessible by entering http://demo-project in your browser’s address bar.

<VirtualHost *>
    DocumentRoot “X:/xampp/htdocs”
    ServerName localhost
    </VirtualHost>

    <VirtualHost *>
    DocumentRoot “X:/xampp/htdocs/mywebsite/webroot”
    ServerName test-project
    </VirtualHost>

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot X:/xampp/htdocs/demo-project/public
    ServerName demo-project

    <Directory “X:/xampp/htdocs/demo-project/public”>
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

Make sure the DocumentRoot exists and matches the Directory and remember the value you set for ServerName.

2. Edit your windows hosts file

Now your apache is ready,but you have to tell your system what to do if you enter http://demo-project in your browser.The most simple way to deal this is to update your hosts file you can find it from here.

C:WINDOWSsystem32driversetc

(Path wil be different if windows installed else where)

The file is just a simple text file which contains IP-to-hostname mappings. Edit the file with a text editor and append a new line which maps the hostname you specified in apache’s ServerName-directive to 127.0.0.1. You can place it just under the existing one which defines localhost. In the end, your file could look like this:

# some comments

127.0.0.1        localhost
127.0.0.1        test-project
127.0.0.1        demo-project

Restart your Apache Server in order to load the new configuration and enjoy