How to Setup Virtual Web Hosting

Apache is a Free Web Server that runs on the Linux Operating System

© Fleur Hupston

Nov 1, 2009
Virtual Web Hosting, paulaeastman007
Setting up virtual web hosting on apache is one way to host more than one web site per IP address, thus providing cost effective web hosting.

Usually each domain or web address needs it's own IP address. When a user types in a web site address into the address bar in the browser and submits the request to the Internet, a “DNS” or Domain Name Server will resolve the “human readable” name to an IP address.

The IP address, in turn, is linked to a network card on a web server. The web server will server the default web page residing on the server to the browser requesting the web site. Under normal circumstances this would mean one web site per IP address. Virtual hosting allows multiple web sites to exist on one web server and share one IP address between them.

How the Virtual host Server Knows Which Website the Browser is Requesting

When a browsers request is relayed on to the web server by means of the DNS resolution to the IP address of the hosting server, it includes the desired web site address in the headers of that request. The web server reads these headers and can tell which web site is being requested, even though there are multiple web sites behind the one network card.

How to Setup Virtual web Hosting on an Apache Server

Setting up virtual web hosting on an apache server is fairly easy. The following step by step guide assumes the Linux and Apache are already installed and running correctly.

Step 1 – Create a directory per web site.

Create a folder or directory for each web site to be hosted on the web server. This should be done in the web servers default directory that apaches uses for web sites. For example, SuSE keeps web sites in the /srv/www directory, so one could create folders as follows, /srv/www/website_a/ and /srv/www/website_b/

Copy the content of each web site into their respective folders.

Step 2 – Create a config file for each virtual web site.

This can be done by copying the template “vhost.template” found in the /etc/apache2/vhosts.d/ and renaming it to the nameofwebsite.conf

Edit this file to suit the requirements of the web site. A sample of this file is shown below:

<VirtualHost website_a.com:80>

ServerName website_a.com

DocumentRoot /srv/www/website_a

ErrorLog /var/log/apache2/website_a_error_log

CustomLog /var/log/apache2/website_a_access_log combined

UseCanonicalName On

ScriptAlias /cgi-bin/ “/srv/www/cgi-bin”

<Directory “/srv/www/cgi-bin”>

AllowOverride None

Options +ExecCGI –Includes

Order allow,deny

Allow from all

</Directory>

<Directory “/srv/www/website_a/”>

AllowOverride None

Options Indexes FollowSymLinks

Order allow,deny

Allow from all

</Directory>

One file needs to be created for each virtual web site

Step 3 – Edit the /etc/apache2/listen.conf file

edit /etc/apache2/listen.conf and add a line in for each virtual web site as the following example shows:

NameVirtualHost website_a.com:80

Step 4 – Test and restart apache

Test the configuration by typing the following at the command prompt:

apache2ctl configtest

If no errors are reported, restart apache and test the apache virtual host by typing the addresses for the added sites in a browser.

Linux provides a stable and robust platform for hosting a company's web site. As can be seen from this and other articles, it is easy to set up an Apache web server without needing advanced Linux knowledge.

An added benefit is that Apache supports virtual web hosting. This means that a small IT support company can host their clients web sites at a reasonable cost.


The copyright of the article How to Setup Virtual Web Hosting in Internet is owned by Fleur Hupston. Permission to republish How to Setup Virtual Web Hosting in print or online must be granted by the author in writing.


Virtual Web Hosting, paulaeastman007
Linux Web Hosting, notacias
Apache Server, internetuts
Virtual Web Hosting, ilco
Inexpensive Web Hosting, lezoah


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo