Wednesday, March 04, 2009

Setting up virtual host on Apache using xampp on windows

It is a very simple process to set up a virtual host on apache web server.
To do this go to \apache\conf\extra and open httpd-vhosts.conf in your favorite (or any) text editor.

Uncomment NameVirtualHost *:80
will enable -based virtual hosting in apache.

Now make entry for your virtual directory like follows:

ServerAdmin viresh@example.com
DocumentRoot D:/xampp/htdocs/viresh
ServerName viresh


Also keep an entry for your default location:


ServerAdmin viresh@example.com
DocumentRoot D:/xampp/htdocs/
ServerName localhost


Now save the file and close it.

Now go to :\WINDOWS\system32\drivers\etc\
open hosts file in a text editor
make an entry for the virtual directory you added like:

127.0.0.1 localhost
127.0.0.1 viresh

Now restart apache.

You can open your sites in browser like:

http://viresh
and
http://localhost

Both will open the sites configured in the DocumentRoot variable of virtual host above.