Tips For Linux

>> Installing and Configuring Apache Web Server - Part 1

This article explains the installation and configuration of the Apache Web Server which is probably the most popular Web Server. This entire article has been written with a typical home user in mind. Hence all the details about security and such related aspects that would come into the picture if it were to be used as a full fledged Web Server which is to be connected to the Internet permanently, are not dealt in great detail in this article.

This article helps any user on his home computer to setup Apache Web Server, configure it and get it working perfectly well for all his learning / programming purposes.

This is article explains the following about Apache Webserver
- Downloading the Apache Web Server Software
- Explains the directory structure of Apache Web Server
- Starting - Stopping - Restarting the Apache Web Server
- A detailed look at the Apache Web Serve Configuration file - httpd.conf
- Creating User directories for User Homepages
- Checking Log files to detect any problems

I may add more sections to this articles later on. So do check some time later.

I call this a Special Guide since it covers the configuration of the Apache Web Server in great detail. Unlike other articles, this article is a complete guide in itself.

Downloading The Apache Web Server

You can download Apache Server from many sites on the Internet. You would get the most recent version at www.apache.org . This is the official site for Apache. Also you could check popular software download sites such as www.download.com or www.tucows.com or www.davecentral.com . I got my copy from a CD that was bundled along with a computer magazine. You get the software in many versions (RPM format, source in tgz, etc.). The one that I have is the source and is named ' apache_1.3.14.tar.gz ' . This is a slightly old version, but it is more than sufficient for all my programming needs as a average web developer.

You would have to unzip this file using ' tar -xfvz apache_1.3.14.tar.gz ' command. Once this is done you have to install the software using the famous 3 commands configure, make & make install . Successful completion of the above steps will make you ready for the rest of this article.

Note :
In case you are not familiar with the configure, make & make install procedure, refer to Article No. 27 which explains this procedure in detail.

Directory Structure of Apache Web Server

Once you have installed the software you would see that a lot of files have been installed in various locations. Here is a summary of those files

/home/httpd : Contains a lot of icons and the default html pages that the server sends to the client.
/etc/httpd/conf : Apache configuration files are stored in this directory.
/etc/rc.d : This directory maintains a list of services to be started every time Linux boots depending on the run level. Apache adds its own entries in the various subdirectories within this directory to start, stop the Apache Web server.

You can change the settings that Apache uses by editing the file /etc/httpd/conf/httpd.conf . This is explained in detail in the later sections of this article.

Note : You might have seen a srm.conf and access.conf file present in the /etc/httpd/conf directory. The older versions of Apache Server used these files for various settings. The newer version of Apache server has kept these files empty and simply added all the settings in the httpd.conf file itself to avoid confusion. So in the new version these files are of no significance.

Starting - Stopping - Restarting the Apache Web Server

To test Apache Server you can start Apache server as follows
# httpd start

Note that you must be the superuser to start the Apache server. Since if you want Apache to respond to requests at port 80 (the default http port) then only the superuser can bind Apache server to port 80 since it is a privileged port. Besides this if you start Apache as normal user it would run with the UID/GID of that user and this is not the right way to run the Server.

Alternatively in case the above command gives you an error you could try the following
# /etc/rc.d/init.d/http start

To stop the server you can type the following
# httpd stop

Once again in case the above doesn't work then you could try typing the following
# /etc/rc.d/init.d/http stop

To restart the server after you make any changes to the configuration files, you can type this simple command
# /etc/rc.d/init.d/http restart

The above command would stop the running server and then once again start the server.

Some error messages you may face

' httpd: could not open document configuration file '
' fopen : no such file or directory '
Both these are problems with the path that has been set. Remember that Apache finds everything relative to the DocumentRoot directive set in the httpd.conf file. So see to it that there is no mistake in setting that value. You can read more about the DocumentRoot directive in the next part of this article. Just remember that this problem is because of wrong setting in the configuration file.

' httpd : could not bind to port 80 '
' bind : operation not permitted '

This is mostly because of running Apache as a normal user and not the superuser. To access port 80 you must be superuser or any other user with the privileges as the superuser.

Goto Part 2 of this article

Tips For Linux © All Copyrights Reserved