Xampp and Virtual Hosts

In the process of setting up my web server to host my blog and web page I was trying to figure out how to make this work.  After consulting an Apache manual it gave me a good idea of how to add virtual hosts into the httd.conf file.  However xampp is a little different and uses a vhost.conf file to configure the virtual hosts.  To add hosts to the vhost.conf file is relitively easy using the following format.  First the vhost.conf file is located in the /xampp/apache/conf/extras folder.  It will have the basic format already typed in you just have to modify and uncomment the lines.  It will look like the following:

# Use name-based virtual hosting.
##NameVirtualHost *:80

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host.example.com
##    DocumentRoot /www/docs/dummy-host.example.com
##    ServerName dummy-host.example.com
##    ServerAlias www.dummy-host.example.com
##    ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
##    CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common

Basically just some tweaking of this example will square you away.  There are several ways to do it and I used the host name method to build the virtual hosts.  Before you configure this file you should back it up and also create the directories that you will install the web pages to, remember they need to be in two seperate directories.  Once I did that I simple edited the vhosts file the following way:

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot c:/xampp/blog/
ServerName blog.ogwatermelon.com
<Directory C:/xampp/blog>
Options Includes Follow SymLinks Indexes
AllowOverride All
Order allow,deny
Allow from all

The server name and document root are all pretty straight forward, but the <directory>  portion is used to address a permissions issues that is set forward in the httd.conf file.  I run xampp on a Windows machine and this works great.  I also saw parts where people added the server names into the Windows host file in c:\windows\system32\drivers\etc.  This will allow for access on that machine using the web browser, however I didn’t do this and allowed my dns to handle the resolution.  I have had no problems.  Finally it is important to know that once you build virtual hosts in the vhost file the web page configuration in the httd.conf file is no longer used.  So if you had a site already configured in that file you will need to add it as one of the virtual hosts.  I hope this will help anyone who is trying to learn virtual host using apache as part of the xampp installation.

You may also like...

Leave a Reply

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

Time limit is exhausted. Please reload the CAPTCHA.