Tuesday, February 17, 2009

Virtual Hosting in Apache

Virtual hosting is the ability of webserver to host more than one domain. The Apache webserver supports virtual hosting. Here are the steps on how to do it.

Considerations:
The web pages will be stored in the home folder of the user such as "/home/bse/www/html". Normally, Apache locates the web pages under the directory "/var/www/html".

I am using CentOS 5.0 (http://www.centos.org) as my operating system of choice.

This setup assumes that you are connected to the Internet.

Here are the steps...

Step 1:
Download the Apache software as follows:


#yum install httpd


Step 2:
Create the virtual file "virtual.conf" under the directory "/etc/httpd/conf.d". The "virtual.conf" file should read as follows:



ServerName idep01.bse.deped.gov.ph

< Directory /home >
Order Deny,Allow
Allow from all
DirectoryIndex index.html index.htm index.php index.phtml
< /Directory >

NameVirtualHost *:80

< VirtualHost *:80 >
ServerName www.bse.deped.gov.ph
DocumentRoot /home/bse/www/html
ErrorLog /home/bse/www/logs/error_log
TransferLog /home/bse/www/logs/access_log
< /VirtualHost >



Step 3:
Create the user and folders for the web pages as follows:


# adduser bse
# mkdir /home/bse/www
# mkdir /home/bse/www/html
# mkdir /home/bse/www/logs
# touch /home/bse/www/logs/error_log
# touch /home/bse/www/logs/access_log


Step 4:
Change the ownership and permissions of the "bse" user and its home folders. I assume that Apache is owned by the user "apache" and group "apache". Here are the commands:


# chown -R bse.apache /home/bse
# chmod -R 755 /home/bse


Step 5:
Copy a test page with the filename "index.html" to the directory "/home/bse/www/html".

Step 6:
Start the Apache web server as follows:


# /etc/rc.d/init.d/httpd start


Verify if you got it right by pointing your browser to the web address of the Apache webserver.

No comments: