Apache Web Server

Howto install an Apache Web Server on a Linux Server

Installing Apache Web Server

The Apache Web Server is one of the most used web server on the World Wide Web. Apache is responsible for serving many of the pages you view on the internet. Apache is also used as a local web server on Linux distributions. Many software packages rely on a web server to provide their configuration/administration interfaces. phpMyAdmin and Nagios Monitoring tool both require the Apache Web Server to be installed. Quite often the Apache Web Server will be automatically installed with applications like Nagios and phpMyAdmin. However, it is quite easy to install the web server directly from your Linux distributions repositories if it is not already installed. In the following example we are going to use a CentOS server.

Centos/RHEL installation

To install an Apache web server, issue the following command: yum install httpd

[root@centos ~]# yum install httpd
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirror.sov.uk.goscomb.net
 * extras: centos.serverspace.co.uk
 * updates: mirror.sov.uk.goscomb.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i686 0:2.2.15-28.el6.centos will be installed
--> Processing Dependency: httpd-tools = 2.2.15-28.el6.centos for package: httpd-2.2.15-28.el6.centos.i686
--> Processing Dependency: libaprutil-1.so.0 for package: httpd-2.2.15-28.el6.centos.i686
--> Processing Dependency: libapr-1.so.0 for package: httpd-2.2.15-28.el6.centos.i686
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-28.el6.centos.i686
--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-28.el6.centos.i686
--> Running transaction check
---> Package apr.i686 0:1.3.9-5.el6_2 will be installed
---> Package apr-util.i686 0:1.3.9-3.el6_0.1 will be installed
---> Package apr-util-ldap.i686 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.i686 0:2.2.15-28.el6.centos will be installed
---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package            Arch        Version                      Repository    Size
 httpd              i686        2.2.15-28.el6.centos         updates      828 k
Installing for dependencies:
 apr                i686        1.3.9-5.el6_2                base         129 k
 apr-util           i686        1.3.9-3.el6_0.1              base          89 k
 apr-util-ldap      i686        1.3.9-3.el6_0.1              base          15 k
 httpd-tools        i686        2.2.15-28.el6.centos         updates       73 k
 mailcap            noarch      2.1.31-2.el6                 base          27 k

Transaction Summary
Install       6 Package(s)

Total download size: 1.1 M
Installed size: 3.4 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
updates/prestodelta                                      | 359 kB     00:00     
Processing delta metadata
Package(s) data still to download: 1.1 M
(1/6): apr-1.3.9-5.el6_2.i686.rpm                        | 129 kB     00:00     
(2/6): apr-util-1.3.9-3.el6_0.1.i686.rpm                 |  89 kB     00:00     
(3/6): apr-util-ldap-1.3.9-3.el6_0.1.i686.rpm            |  15 kB     00:00     
(4/6): httpd-2.2.15-28.el6.centos.i686.rpm               | 828 kB     00:00     
(5/6): httpd-tools-2.2.15-28.el6.centos.i686.rpm         |  73 kB     00:00     
(6/6): mailcap-2.1.31-2.el6.noarch.rpm                   |  27 kB     00:00     
Total                                           1.3 MB/s | 1.1 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : apr-1.3.9-5.el6_2.i686                                       1/6 
  Installing : mailcap-2.1.31-2.el6.noarch                                  2/6 
  Installing : apr-util-1.3.9-3.el6_0.1.i686                                3/6 
  Installing : apr-util-ldap-1.3.9-3.el6_0.1.i686                           4/6 
  Installing : httpd-tools-2.2.15-28.el6.centos.i686                        5/6 
  Installing : httpd-2.2.15-28.el6.centos.i686                              6/6 
  Verifying  : apr-util-1.3.9-3.el6_0.1.i686                                1/6 
  Verifying  : apr-1.3.9-5.el6_2.i686                                       2/6 
  Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.i686                           3/6 
  Verifying  : httpd-tools-2.2.15-28.el6.centos.i686                        4/6 
  Verifying  : mailcap-2.1.31-2.el6.noarch                                  5/6 
  Verifying  : httpd-2.2.15-28.el6.centos.i686                              6/6 

  httpd.i686 0:2.2.15-28.el6.centos                                             

Dependency Installed:
  apr.i686 0:1.3.9-5.el6_2              apr-util.i686 0:1.3.9-3.el6_0.1         
  apr-util-ldap.i686 0:1.3.9-3.el6_0.1  httpd-tools.i686 0:2.2.15-28.el6.centos 
  mailcap.noarch 0:2.1.31-2.el6        


The Apache web server is known under CentOS as "httpd". To make sure our web server is started at a reboot, we must use the chkconfig command to add it to the appropriate runlevels. The command used to accomplish this is: chkconfig --level 235 httpd on

chkconfig --levels 235 httpd on

To confirm our web server is set to start with the runlevels 2,3 and 5 we can issue the following command:

[root@centos ~]# chkconfig --list | grep httpd
httpd          	0:off	1:off	2:on	3:on	4:off	5:on	6:off

Testing the Web Server

To test that the web server is running, we can issue the command: service httpd status

If the server is not active, you will need to restart the service with the following command: service httpd restart

[root@centos ~]# service httpd status
httpd (pid  1399) is running...

As a test, you can point your browser to the IP address of your server. In this example, our IP address is

Apache Web Server

Configuration Files

The main configuration files can be found under the following location: /etc/httpd/conf/httpd.conf The main document area is located in the following path: /var/www/html

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "/var/www/html"

If you wish to test this location, then you can create a simple "index.html" file and place this in the above location.
Test index.html:

<meta content="text/html; charset=ISO-8859-1"
<title>www.landoflinux.com Test Page</title>
<big><big><big><span style="font-weight: bold;">Welcome to my test
index.html page</span></big></big></big><br>

The output from the above html would give us a simple page of:

Apache Web Server

Further Reading

For more information on the configuration of Apache, visit the Apache homepage: Apache website

There are also many books available on the subject of Apache Web Servers and their configuration. Visit our books area and search for Apache: Linux Book Store