Posted: September 7, 2010 in REDHAT 5 LinUX



Apache is probably the most popular Linux-based Web server application in use. Once you have DNS correctly setup and your server has access to the Internet, you’ll need to configure Apache to accept surfers wanting to access your Web site.

This chapter explains how to configure Apache in a number of commonly encountered scenarios for small web sites.

Download and Install The Apache Package

Most RedHat and Fedora Linux software products are available in the RPM format. When searching for the file, remember that the Apache RPM’s filename usually starts with the word httpd followed by a version number, as in httpd-2.0.48-1.2.rpm. It is best to use the latest version of Apache.

When searching for the file, remember that the Redhat / Fedora Apache RPM package’s filename usually starts with the word httpd followed by a version number, as in httpd-2.0.48-1.2.rpm. With Ubuntu / Debian the package name will have the apache prefix instead.

Note: Unless otherwise stated, the sample configurations covered in this chapter will be for Redhat / Fedora distributions. If you use Debian / Ubuntu, don’t worry, there will be annotations to make you aware of the differences.



How To Get Apache Started

Setting up the Apache server is easy to do, but the procedure differs between Linux distributions.

Redhat / Fedora / Centos

Use the chkconfig command to configure Apache to start at boot:

[root@bigboy tmp]# chkconfig httpd on

Use the httpd<code> init script in the <code>/etc/init.d directory to start,stop, and restart Apache after booting:

[root@bigboy tmp]# /etc/init.d/httpd start

[root@bigboy tmp]# /etc/init.d/httpd stop

[root@bigboy tmp]# /etc/init.d/httpd restart

You can test whether the Apache process is running with

[root@bigboy tmp]# pgrep httpd

General Configuration Steps

The configuration file used by Apache is /etc/httpd/conf/httpd.conf in Redhat / Fedora distributions. As for most Linux applications, you must restart Apache before changes to this configuration file take effect.

Where To Put Your Web Pages

All the statements that define the features of each web site are grouped together inside their own <VirtualHost> section, or container, in the httpd.conf file. The most commonly used statements, or directives, inside a <VirtualHost> container are:

  • servername: Defines the name of the website managed by the <VirtualHost> container. This is needed in named virtual hosting only, as I’ll explain soon.
  • DocumentRoot: Defines the directory in which the web pages for the site can be found.

By default, Apache searches the DocumentRoot directory for an index, or home, page named index.html. So for example, if you have a servername of with a DocumentRoot directory of /home/www/site1/, Apache displays the contents of the file /home/www/site1/index.html when you enter in your browser.

Some editors, such as Microsoft FrontPage, create files with an .htm extension, not .html. This isn’t usually a problem if all your HTML files have hyperlinks pointing to files ending in .htm as FrontPage does. The problem occurs with Apache not recognizing the topmost index.htm page. The easiest solution is to create a symbolic link (known as a shortcut to Windows users) called index.html pointing to the file index.htm. This then enables you to edit or copy the file index.htm with index.html being updated automatically. You’ll almost never have to worry about index.html and Apache again!

This example creates a symbolic link to index.html in the /home/www/site1 directory.

[root@bigboy tmp]# cd /home/www/site1
[root@bigboy site1]# ln -s index.htm index.html
[root@bigboy site1]# ll index.*
-rw-rw-r--    1 root     root        48590 Jun 18 23:43 index.htm
lrwxrwxrwx    1 root     root            9 Jun 21 18:05 index.html -> index.htm
[root@bigboy site1]#

The l at the very beginning of the index.html entry signifies a link and the -> the link target.

The Default File Location

By default, Apache expects to find all its web page files in the /var/www/html/ directory with a generic DocumentRoot statement at the beginning of httpd.conf. The examples in this chapter use the /home/www directory to illustrate how you can place them in other locations successfully.

File Permissions And Apache

Apache will display Web page files as long as they are world readable. You have to make sure you make all the files and subdirectories in your DocumentRoot have the correct permissions.

It is a good idea to have the files owned by a nonprivileged user so that Web developers can update the files using FTP or SCP without requiring the root password.

To do this:

  1. Create a user with a home directory of /home/www.
  2. Recursively change the file ownership permissions of the /home/www directory and all its subdirectories.
  3. Change the permissions on the /home/www directory to 755, which allows all users, including the Apache’s httpd daemon, to read the files inside.
[root@bigboy tmp]# useradd -g users www
[root@bigboy tmp]# chown -R www:users /home/www
[root@bigboy tmp]# chmod 755 /home/www

Now we test for the new ownership with the ll command.

[root@bigboy tmp]# ll /home/www/site1/index.*
-rw-rw-r--    1 www     users       48590 Jun 25 23:43 index.htm
lrwxrwxrwx    1 www     users           9 Jun 25 18:05 index.html -> index.htm
[root@bigboy tmp]#

The conf.d Directory

Files in the /etc/httpd/conf.d (Redhat / Fedora) or the /etc/apache*/conf.d (Debian / Ubuntu) directory are read and automatically appended to the configuration in the httpd.conf file every time Apache is restarted. In complicated configurations, in which a Web server has to host many Web sites, you can create one configuration file per Web site each with its own set of <VirtualHost> and <Directory> containers. This can make Web site management much simpler. To do this correctly:

  1. Backup your httpd.conf file, in case you make a mistake.
  2. Create the files located in this directory that contain the Apache required <VirtualHost> and <Directory> containers and directives.
  3. If each site has a dedicated IP address, then place the NameVirtualHost statements in the corresponding conf.d directory file. If it is shared, it’ll need to remain in the main httpd.conf file.
  4. Remove the corresponding directives from the httpd.conf file.
  5. Restart Apache, and test.

The files located in the conf.d directory don’t have to have any special names, and you don’t have to refer to them in the httpd.conf file.

Type in or copy/paste the configuration data below. Be sure to replace yourhostname with your system’s hostname or IP address, ServerAdmin with your email address, ServerName and ServerAlias with your real domain name, and your-domain with the directory name you created earlier for your web site. When you’re done, save your changes wq!

<VirtualHost yourhostname:80>




DocumentRoot /www/your-domain/html

ScriptAlias /cgi-bin/ /www/your-domain/html/cgi-bin/

ErrorLog /www/your-domain/logs/error_log

CustomLog /www/your-domain/logs/access_log combined


I’ll clarify what each line does in the virtual host configuration file between the <VirtualHost></VirtualHost> tags.

  • ServerAdmin is used to specify the server administrator’s email address. User’s will see this address on server generated error pages.
  • ServerName is the name of the server or DNS name. Apache will match this name against the HTTP host header sent by the user’s browser. If it’s a match then this is the configuration data used to process the request.
  • ServerAlias is identical to ServerName except ServerName is used once and ServerAlias can be used many times. If your web site will respond to more than one DNS name, make sure you use one ServerName directive and all other names are specified using ServerAlias. DNS names can be separated by commas for a single ServerAlias directive (ServerAlias dns_name1,dns_name2,dns_name3) or you can use many ServerAlias directives for each DNS name placed on a line each their own.
  • DocumentRoot defines the file system path to where the web page files are located. This is the same directory where you will place your HTML, PHP, and image files. For our setup, this is the /www/your-domain/html directory.
  • ScriptAlias defines the directory for executing cgi scripts, commonly known as cgi-bin. It takes two parameters with the first being the cgi-bin directory from your web site root path and the second being the full physical directory path on the filesystem. You can have as many cgi-cin directories as you need and they don’t need to be called cgi-bin.
  • ErrorLog defines the file to log any errors Apache encounters. Errors can include PHP script failures and files that don’t exist.
  • CustomLog defines the file to log any requests to the server. Requests include accessing pages, images, and other files like robots.txt. The second parameter sets the log entry format. We use the combined format since it is used by many Web Server Log Analysis scripts like Awstats.

The Apache Status Log Files

The /var/log/httpd/access_log file is updated after every HTTP query and is a good source of general purpose information about your website. There is a fixed formatting style with each entry being separated by spaces or quotation marks

The Apache Error Log Files

The /var/log/httpd/error_log file is a good source for error information. Unlike the /var/log/httpd/access_log file, there is no standardized formatting.

Typical errors that you’ll find here are HTTP queries for files that don’t exist or forbidden requests for directory listings. The file will also include Apache startup errors which can be very useful.

The /var/log/httpd/error_log file also is the location where CGI script errors are written. Many times CGI scripts fail with a blank screen on your browser; the /var/log/httpd/error_log file most likely lists the cause of the problem.


Web sites both personal and commercial can be very rewarding exercises as they share your interests with the world and allow you to meet new people with whom to develop friendships or transact business.

Unfortunately, even the best Web sites can be impersonal as they frequently only provide information that the designer expects the visitor to need. E-mail, although ancient in comparison to newer personalized interactive Internet technologies, such as IP telephony and instant messaging, has the advantage of being able to relay documents and other information without interrupting the addressee. This allows them to schedule a response when they are better prepared to answer, a valuable quality when replies need to be complex.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s