Hosting more than one webpage using Apache (Virtual hosts)

Posted: August 3, 2008 in Non Insteon Programming
Tags: , , , , , , , , , ,

In trying to consolidate all the PC’s and other OS I have at home into one machine I ran into a small problem.  First I was finally able to remove my good old 2k3 test server.  This server hosted Exchange, DNS, DHCP, and 5 webpages.  With that said, the pc replacing it only had XP on it and really was going to let my trusty D-link take care of DNS,DHCP and all the other goodies.  And I had no need to exchange

But once I came to migrate my webpages, XP’s IIS only allows you to run one webpage!?.  Ok np, all my webpages are PHP,MySql and other goodies so I really had no need for IIS nor .NET framework.  So I downloaded a copy of XAMP which has everything ready to go.  You can find that here.  This package includes

Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, JpGraph, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql.

Its more than all the necessary tools in one easy to use program, and since all its components are free well its free for you to.

Go ahead and install it, you’ll have your webpage setup in no time!.  Lets say you have your router allowing port 80 out to the internet so you want to host more than one page (I’ll explain the port opening on another document).

For the example I have one page pointed to http://www.site1.com and http://www.site2.com on the same XP in windows

  • Install Xamp and test you can see the webpage.  In my case I installed it on F:\ drive which we’ll use from now on, you can use C:\ if you like. Coming for the server side, I keep my system files separate from the program files.
  • Look for your apache http.conf file, in my  case it was found here “E:\xampp\apache\conf”, open it with notepad.  Were going to give Apache permissions to the webpage root folder first.

Add the following lines in this case my files are located on E:/shared/WebSite-Live/site1_files and the second site on Site2_files

#--------------------------- MAKE SURE YOU GIVE ACCESS TO APACHE TO THE DIRECTORY 
<Directory "E:/Shared/WebSites-Live/site1_files">
  Order allow,deny
    Allow from all
</Directory>

#--------------------------- MAKE SURE YOU GIVE ACCESS TO APACHE TO THE DIRECTORY 
<Directory "E:/Shared/WebSites-Live/site2_files">
  Order allow,deny
    Allow from all
</Directory>

For the sake of simplicity we’ll allow All to view this folder.

  • Now we are going to go ahead and create the virtual host.  Look for this file called ‘httpd-vhosts.conf’ this can be part of the original http.conf file but is separated in the install of xamp , so we will modify that file directly, that is found ‘e:\xamp\apache\conf\extra’. Go ahead and open it with Notepad
#'---------The first section we will leave alone since its the main page, and will only load from the localhost 127.0.0.1
<VirtualHost 127.0.0.1>
 ServerAdmin webmaster@dummy-host.example.com
 DocumentRoot "e:/xampp/htdocs"
 ServerName localhost
 ServerAlias localhost
 </VirtualHost>
 #------------------- HERE WE SPECIFY THE SECOND VIRTUAL HOST WHICH IS OPEN TO EVERYONE
<VirtualHost *>
 ServerAdmin webmaster@dummy-host.example.com
 DocumentRoot "e:/Shared/WebSites-Live/site1_files"
 ServerName www.site1.com
 <Directory "e:/Shared/WebSites-Live/site1_files">
 Options All Includes Indexes
 </Directory>
 </VirtualHost>
 #------------------- HERE WE SPECIFY THE THIRD VIRTUAL HOST WHICH IS OPEN TO EVERYONE
<VirtualHost *>
 ServerAdmin webmaster@dummy-host.example.com
 DocumentRoot "e:/Shared/WebSites-Live/site2_files"
 ServerName www.site2.com
 <Directory "e:/Shared/WebSites-Live/site2_files">
 Options All Includes Indexes
 </Directory>
 </VirtualHost>
  • Either using the Xamp console or going to control panel then services restart your Apache service and your set!

Note: If your not exposing your Pc out into the internet you can still host more than one site, you may need to play with each PC’s ‘hosts’ file to point them to the PC hosting the sites.

Advertisements
Comments
  1. […] Hosting more than one webpage using Apache (Virtual hosts)In trying to consolidate all the PC’s and other OS I have at home into one machine I ran into a small problem. First I was finally able to remove my good old 2k3 test server. This server hosted Exchange, DNS, DHCP, and 5 webpages. … […]

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s