Virtual Hosting in Apache Web Server On Debian

When setting up web servers, most have chosen to use Linux not only because it is free, open-source, and made for networking but also because it works best with this “little” web server software that more than half of the world's websites depend upon. I'm talking about Apache, which some of the most popular GNU/Linux distributions (Debian, Ubuntu, Centos, Red Hat, Fedora, SUSE, Mandriva, etc) have included in their respective applications repositories and is pretty much packaged to work well to corresponding distros.

Note: This tutorial doesn't discuss the installation of Apache web server since I assumed that you already know how to use your package manager to install it. I'm using Debian Sid/Unstable, so if you are running Apache on any Debian derivative you can more or less follow the instructions here.

Most Linux users are satisfied with just installing the Apache web server and use these methods/configurations for accessing the websites made:

1.Default site configuration found in /etc/apache2/sites-available/default. Web site directories and files reside in /var/www/. You need root account to add, delete and modify website directories and files.

2.Activating the UserDir directive (covered in another article)

The first set up, which is the default setup in Debian, lets you access the website thru any of these addresses:

While this set up is sufficient enough to run any or all web sites you can think of, it kind of fall short of feeling that you are using the real thing. One will notice that those URLs/addresses don't look like addresses you would see in the actual World Wide Web. Even if you are in a development stage and you don't intend to open your computer for public access, it feels a little short. What about doing some website for LAN, an intranet site – you don't expect users to memorize numbers or use localhost for that will definitely discourage users from accessing your website. What if you have a lot of website to host for different reasons and content? Most modern and not so modern computers can host a lot of websites for Apache web server because they are programmed to handle more than one websites.

This article covers a tutorial on setting up your GNU/Linux Debian Sid computer to host plenty of websites with their own website address, much like those found in the real world wide web. This tutorial does not cover public access and is limited to local area network (LAN) access only. My purpose for setting this up includes the following reasons but not limited to:

* Intranet services with URLs that looks like those found in World Wide Wide (WWW)when accessed from LAN.

* Staging area of websites that looks like WWW URLs

* Setting up many different websites in your web server with their own server/website names.

In order for other computers to access your server(s)' local web sites, it is assumed that your LAN has a local DNS server where you can register all of your web sites' names.

Step 1. Decide on where you would place your web site files and directories. Although this is not mandatory, it is strongly recommended for efficient file management. I'm using /home/<user_name>/webdocs/. Replace <user_name> with your own username. All of your web sites will look like the following:

* /home/bencanlas/webdocs/site01

* /home/bencanlas/webdocs/site02

* /home/bencanlas/webdocs/site03

* /home/bencanlas/webdocs/site04

* … and so on

Step 2. Make another directory inside webdocs and call it 'logs'. This is where we will place log files. You can specify another directory for this but take note of it.

Step 3. Decide on what name to call/access your website from the browser. For this example, we will call a web site officeblogs. You can name your website any name you wish. It won't leave your local area netwok. Create a directory in /home/bencanlas/webdocs and call it officeblogs.

Step 4. Log into root mode and edit /etc/hosts. Enter the following line:

# your computer's IP address

192.168.1.2

# name of your website

officeblogs

Step 5. Make a specific Apache configuration file for this particular website. You can name the file any name but for this tutorial we will call it officeblogs.conf. Save this in your regular document file. Later, we will copy it into the Apache web server's configuration directories. You can copy the listing below or type it:

d.Execute apache2ctl restart to restart Apache webserver and include officeblog as one of the sites it is serving.

Step 7. To test your newly configured website open up a web browser and enter the URL http://officeblogs to access this website. Of course you need to put some web pages into the officeblogs directory for your site contents.

To add another web site, go back to "Step 3".

Just a reminder, this is not the only way to configure a web server when hosting many websites. If you know an easier or more efficient method, you may share it with us via comment.