Tuesday, February 17, 2009

PHP Support in the Apache Webserver

The following are my notes on PHP support in the Apache Webserver. The Linux box I am using runs on CentOS 5.0 operating system. The following steps assumes that the Linux box is connected to the Internet:


# yum install httpd
# yum install php
# yum install php-mysql
# yum install php-pgsql
# yum install php-mbstring
# yum install php-xmlrpc
# yum install php-gd


Among others, the above commands installs Apache and PHP with support for the MySQL and PostgreSQL databases.

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.

Setting up a Master DNS Server

These are my notes on setting up a master DNS server. DNS is short for Domain Name System. The DNS is responsible for translating computer addresses in the form of numbers into human understandable convention like "www.google.com".

First, my system. The operating system that I am installing to is a CentOS 5.0 Linux box. If you are not familiar with the CentOS Linux distribution, CentOS is generally a "Red Hat Enterprise Product" distribution intended for production deployments without the branding and support of Red Hat. It is in many ways the same as the Red Hat Enterprise Linux product and is related to the Fedora distribution.

Setting up the master DNS server requires the following steps:

Step 1:
Download and install the BIND software. BIND is short for Berkeley Internet Name Domain. I am assuming that you are connected to the Internet. The command to do that is:


# yum install bind
# yum install bind-utils



Step 2:
Create the configuration file "named.conf" in the directory "/etc". The file "named.conf" should read as follows:



zone "0.0.127.in-addr.arpa" {
type master;
file "mylocalhost";
};

zone "bse.deped.gov.ph" {
type master;
notify no;
file "bse.deped.gov.ph";
};

zone "126.126.222.in-addr.arpa" {
type master;
notify no;
file "222.126.126";
};



Step 3:
Create the file "mylocalhost" in the directory "/var/named". The "mylocalhost" file should read as follows:



$TTL 3D
@ IN SOA ns.bse.deped.gov.ph. hostmaster.bse.deped.gov.ph. (
1 ; serial
8H ; Refresh
2H ; Retry
4W ; Expire
1D) ; Minimum TTL

NS ns.bse.deped.gov.ph.

1 PTR localhost.




Step 4:
Create the zone file for the domain like "bse.deped.gov.ph" in the directory "/var/named". The file "bse.deped.gov.ph" should read as follows:




$TTL 3D
@ IN SOA ns.bse.deped.gov.ph. hostmaster.bse.deped.gov.ph. (
19980214 ; serial
8H ; refresh
2H ; retry
4W ; expire
1D) ; minimum TTL

NS ns
MX 10 mail01.bse.deped.gov.ph.
20 mail02.bse deped.gov.ph.

localhost A 127.0.0.1
www A 222.126.126.211

ns A 222.126.126.211
mail01 A 222.126.126.211
mail02 A 222.126.126.212



Step 5:
Create the reverse domain file such as "222.126.126" in the directory "/var/named". The file "222.126.126" should read as follows:



$TTL 3D
@ IN SOA ns.bse.deped.gov.ph. hostmaster.bse.deped.gov.ph. (
19980214 ; serial
8H ; Refresh
2H ; Retry
4W ; Expire
1D ) ; Minimum TTL

NS ns.bse.deped.gov.ph.

211 PTR www.bse.deped.gov.ph.



Step 6:
Start the server as follows:



# /etc/rc.d/init.d/named start
Starting named: [ OK ]


If there are no errors proceed to the next step. If there are errors, double check on the contents of the setup files.

Step 7:
Check the name resolution functionality of your server by using the "nslookup" utility that comes with the "bind-utils" package as follows:



# nslookup www.bse.deped.gov.ph
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: www.bse.deped.gov.ph
Address: 222.126.126.211

# nslookup 222.126.126.211
Server: 127.0.0.1
Address: 127.0.0.1#53

211.126.126.222.in-addr.arpa name = www.bse.deped.gov.ph.