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:WINDOWSsystem32driversetchosts

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:xamppapacheconfextrahttpd-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

# put this anywhere below the line above
ServerAdmin postmaster@testsite
DocumentRoot "C:/MyWebsites/justablog"
ServerName testsite
ServerAlias my.testsite
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" combined

Notice that my test sites is sitting in C:MyWebsitesJustablog 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


<!--?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

Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all

somewhere above

<directory "c:="" xampp="" htdocs"="">

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.

Advertisements
This entry was posted in Software Development and tagged . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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