Custom Search

Friday 7 October 2011

How to install and configure Apache on RedHat

How to install and configure Apache on RedHat and derivatives

In this tutorial, I am going to show you how to install Apache and do the initial configuration for a single site. This is tutorial is intended for those new to Apache.
The steps were performed on Centos 5.3 virtual machine inside vmware player. The main daemon in RedHat and its derivatives is called httpd while its named apache2 in Debian based systems.

1. Install Apache

yum install apache

This will install Apache …..

2. Now checkout which files have been installed with the apache

rpm -ql httpd

/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/proxy_ajp.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs

.......

The file we are concerned with is httpd.conf

3. Open this file in a text editor

nano /etc/httpd/conf/httpd.conf

and check DocumentRoot. This is the location where we have to place our html documents for users to access. In my case, it is

DocumentRoot “/var/www/html”

Think of DocumentRoot as corresponding to what we type before first / in web browser eg www.example.com/.

Next check DirectoryIndex. This directive governs the default file that Apache serves when no specific file is requested by a user.

DirectoryIndex index.html index.html.var

It means that Apache will first look for index.html, if not found, then index.html.var and send it to the requesting browser. For example, typing www.example.com will result in sending index.html or index.html.var to the browser. Any file other than these two needs to be specified explicitly in the browser like www.example.com/test.html. Remember, anything after www.example.com/ are in DocumentRoot (/var/www/html in this case).

We will create a file index.html for our test and place some simple text in it like:

 nano /var/www/html/index.html

and paste the following text into it

<html>
<body>

<h1>My Test page</h1>

</body>
</html>

Save it by pressing

ctrl+w

and then

Enter

4. Type in the IP or host name of your server or just localhost in the browser. Find IP with the following command
ifconfig

and host name with this command

hostname


To configure it to be accessible from outside, you may want an entry in DNS server pointing its domain name to Apache server’s IP.
Apache is configured.

No comments:

Post a Comment