You Are Here: Home » How-To » Networks

How To Setup VirtualHosts, Multiple Websites in XAMPP Apache Server?

By Debjit on December 29th, 2012 
Advertisement

XAMPP provides a full blown Linux Apache MySQL server installation and is a very good way to seup LAMP architecture on your Windows PCs. Although, XAMPP is available for Linux distribution as well, but is not used often as LAMP packages are readily available on Linux distributions.

XAMPP Control Panel 3 Beta

XAMPP Control Panel 3 Beta

In this article we will talk about how to set-up Multiple Websites in XAMPP or any Apache Server. "Multiple Websites" would be the common term for the much appropriate technical term - "VirtualHosts" or "NameVirtualHosts".

We will work through this tutorial based on a real life example. Lets assume we have to work on two development web-based projects on the same apache server - http://project1.dev and http://project2.dev. Also, we are assuming that you have installed xampp in this directory: C:/xampp

Step 1 - After you have successfully installed XAMPP on your Windows system, open the file:

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

This file is your VirtualHosts configuration file and will be referred to in all forthcoming steps.

Step 2 - At around Line number 19, you can find a commented out line that goes like this:

NameVirtualHost *:80

Please make sure that you un-comment this line

Step 3 - Add the first VirtualHost directive for your localhost so that urls like http://localhost or http://127.0.0.1 are still accessible. This is an extremely necessary step and make sure you add this to the VirtualHosts configuration file else you will lose access to the http://localhost.

<VirtualHost *:80>
ServerAdmin postmaster@localhost
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>

Step 4 - Now start adding the directives for your two development project websites:

<VirtualHost project1.dev>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs/project1dev"
ServerName project1.dev
ServerAlias www.project1.dev
ErrorLog "logs/project1.dev-error.log"
CustomLog "logs/project1.dev-access.log" combined
</VirtualHost>

<VirtualHost project2.dev>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs/project2dev"
ServerName project2.dev
ServerAlias www.project2.dev
ErrorLog "logs/project2.dev-error.log"
CustomLog "logs/project2.dev-access.log" combined
</VirtualHost>

We are now set all you have to do is just restart your Apache server and you can star accessing the sites at:  http://project1.dev and http://project2.dev

Advertisement







How To Setup VirtualHosts, Multiple Websites in XAMPP Apache Server? was originally published on Digitizor.com on December 29, 2012 - 2:59 pm (Indian Standard Time)