Virual Hosts in Apache XAMPP in Windows

In previous version of Apache one httpd.conf file was maintained for all setting of the Apache webserver, including Virtual hosts. In later version, this apprach has been changed. It has been made more modular so that httpd.conf file contains a link to Include “conf/extra/httpd-vhosts.conf”.
The virtual host file contains all virtual hosts. By default no virtual hosts are provided. Templates are available though which can be modifed according to the needs. Some tweak of windows host file is needed as well.

Using this appraoch,  you can host a website anywhere on the hard disk, not necessarily only in htdocs folder

Steps

1.  Start with Window host file. Copy


C:\WINDOWS\system32\drivers\etc\hosts

in Window explorer. This file does not has an extension. It will ask you a choice which program to use. Select notepad.

2. Edit the file. Add this entry

127.0.0.1 localhost
127.0.0.1 mytestsite <----- I have added this entry

3. No Go to virtual host files maintained by Apached. They are located in this file

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

Almost all of this file is commented, make sure you added this two entries in this file. Are you can ucomment the existing one and modify it to these (more desirable)

 

NameVirtualHost *:88 # put this in the beginning of the file

Notice that my test sites is sitting in C:\MyWebsites\Justablog\ folder. Use forward slashes instead of backwards.

4. Create this folder and put a test php file in it such as this. Name it index.php


echo "

I am alive

 

";
?>

5. The virtual hosts are not by default linked in the httpd.conf file. Edit the httpd.conf file and search for this string


Include "conf/extra/httpd-vhosts.conf"

If you can’t find it. Search for a smaller part of the above string. If you find it and there is no # symbol ahead of it, leave it as it is. Otherwise remove the # sign.

5. If you restart your apache server at this point and access the site, you will be given access denied error. To fix that you have to add the permission in httpd.conf file (the one you have already opened). Add this somewhere

somewhere above

entry.

At this point you should be all set.

Make sure all directories that are entered in config file are case sensitive, otherwise it will not work.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*