You are on page 1of 5

Installation of the Apache HTTP

The Apache installation can be done using various methods, based on the requirement of the
infrastructure. For example, if you want to run multiple Apache instances on a single machine,
then the Source installation will be used. There are mainly three types of installations done in
various web environments:

1. Source
2. Binary
3. RPM/exe

Note:
Source is preferred by web administrators, as it can be customized based on system
requirements.

Below method was used by me to install http server in sprdneval (192.168.1.189) Oracle Linux Server 6.5

Installing Apache from Source

Just in case you are not happy with the built-in defaults that the binary Apache package forces you to
live with and you want to build your web server software from scratch, you can always obtain the
latest stable version of the program directly from the apache.org web site. The procedure for building
from source is discussed here. Please note that we use the asterisk (*) wildcard symbol to mask the
exact version of httpd software (Apache) that was used. This is done because the exact stable version
of httpd available might be different when you go through the steps. You should therefore substitute
the asterisk symbol with a proper and full version number for the apache/httpd software package. So
for example, instead of writing httpd-2.2.21.tar.gz or httpd-2.4.0.tar.gz, we cheat and
simply write - httpd-2.*.
The most current version will always be available at www.apache.org/dist/httpd/

1. We’ll download the latest program source into the /usr/local/src/ directory from the apache.org web
site. You can use the wget program to do this:
[root@sprdneval src]#
wget http://www.apache.org/dist/httpd/httpd-2.2.31.tar.gz
2. Extract the tar archive. And then change to the directory that is created during the extraction.
[root@sprdneval src]# tar xvzf httpd-2.2.31.tar.gz
[root@sprdneval src]# cd httpd-2.2.31

3. Assuming we want the web server program to be installed under the /usr/local/ httpd/ directory,
we’ll run the configure script with the proper prefix option:
[root@sprdneval httpd-2.2.31]#
./configure --with-included-apr --prefix=/usr/local/httpd
4. Run make.
[root@sprdneval httpd-2.2.31]# make
5. Create the program’s working directory (that is, /usr/local/httpd/), and then run make install:
[root@sprdneval httpd-2.2.31]#
make install
Once the install command completes successfully, a directory structure will be created
under /usr/local/httpd/ that will contain the binaries, the configuration files, the log files, and so on,
for the web server.

[root@sprdneval httpd-2.2.31]# cd /usr/local/httpd


[root@sprdneval httpd]# ls -ltr

drwxr-xr-x 2 root root 4096 Jul 15 21:54 htdocs


drwxr-xr-x 14 root root 12288 Jul 15 21:54 manual
drwxr-xr-x 4 root root 4096 Nov 18 13:16 lib
drwxr-xr-x 2 root root 4096 Nov 18 13:16 modules
drwxr-xr-x 2 root root 4096 Nov 18 13:16 bin
drwxr-xr-x 4 root root 4096 Nov 18 13:16 conf
drwxr-xr-x 3 root root 4096 Nov 18 13:16 error
drwxr-xr-x 3 root root 4096 Nov 18 13:16 icons
drwxr-xr-x 2 root root 4096 Nov 18 13:16 logs
drwxr-xr-x 2 root root 4096 Nov 18 13:16 cgi-bin
drwxr-xr-x 2 root root 4096 Nov 18 13:16 include
drwxr-xr-x 2 root root 4096 Nov 18 13:16 build
drwxr-xr-x 4 root root 4096 Nov 18 13:16 man

Starting up and Shutting Down Apache


Starting up and shutting down Apache on most Linux distributions is easy. To start Apache on a
Fedora system or any other Red Hat–like system, use this command:

service httpd start

On Linux distributions running systemd, you can alternatively start the httpd daemon using
the systemctl command like so:
systemctl start httpd.service
To shut down Apache, enter this command:

service httpd stop

After making a configuration change to the web server that requires you to restart Apache, type this:
service httpd restart

TIP On a system running openSUSE or SLE (SUSE Linux Enterprise), the commands to start and
stop the web server, respectively, are
rcapache2 start
and
rcapache2 stop

TIP On a Debian system such as Ubuntu, you can start Apache by running:
sudo /etc/init.d/apache2 start
The Apache daemon can be stopped by running:
sudo /etc/init.d/apache2 stop

Starting Apache at Boot Time


After installing the web server, it’s reasonable to assume that you want the web service to be
available at all times to your users; you will therefore need to configure the system to start the service
automatically for you between system reboots. It is easy to forget to do this on a system that has been
running for a long time without requiring any reboots, because if you ever had to shut down the
system due to an unrelated issue, you might be baffled as to why the web server that has been
running perfectly since installation without incident failed to start up after starting the box. So it is
good practice to take care of this during the early stages of configuring the service.

Most Linux flavors have the chkconfig utility available, which can be used for controlling which
system services start up at what runlevels.

To view the runlevels in which the web server is configured to start up, type

my server : --
[root@sprdneval httpd]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on
6:off

chkconfig --list httpd


httpd 0:off 1:off 2:off 3:off 4:off
5:off 6:off

This output shows that the web server is not configured to start up in any runlevel in its out-of-
the-box state. To change this and make Apache start up automatically in runlevels 2, 3, 4, and 5, type
this:

chkconfig httpd on

On Linux distributions running systemd, you can alternatively make the httpd daemon
automatically start up with system reboots by issuing the systemctl command, like so:

systemctl enable httpd.service

In Ubuntu, you can use either the sysv-rc-conf or the update-rc.d utility to manage the runlevels
in which Apache starts up.

NOTE Just in case you are working with an Apache version that you installed from source, you
should be aware that the chkconfig utility will not know about the start-up and shutdown scripts for
your web server unless you explicitly tell the utility about it. And as such, you’ll have to resort to
some other tricks to configure the host system to bring up the web server automatically during
system reboots. You may easily grab an existing start-up script from another working system (usually
from the /etc/init.d/ directory) and modify it to reflect correct paths (such as /usr/local/httpd/) for
your custom Apache setup. Existing scripts are likely to be called httpd or apache2.

Testing Your Installation


You can perform a quick test of your Apache installation using its default home page. To do this,
first confirm that the web server is up and running using the following command:

[root@sprdneval httpd]# service httpd status


httpd (pid 3665) is running...

You can also issue a variation of the systemctl command on systemd-aware systems to view a nice
synopsis (cgroup information, child processes, and so on) of the Apacheserver status, like so:

systemctl status httpd.service

TIP If you are working with a version of Apache that you built from source, the working directory
from which web pages are served is <PREFIX>/htdocs. For example, if your installation prefix
is /usr/local/httpd/, then web pages will, by default, be under /usr/local/httpd/htdocs/.

To find out if your Apache installation went smoothly, start a web browser and tell it to visit the
web site on your machine. To do this, simply type http://www.localhost (or the Internet Protocol
Version 6 [IPv6] equivalent, http://[::1]/) in the address bar of your web browser. You should see a
page stating something to the effect that “your Apache HTTPserver is working properly at your site.”
If you don’t see this, retrace your Apache installation steps and make sure you didn’t encounter any
errors in the process. Another thing to check if you can’t see the default web page is to make sure
that you don’t have any host-based firewall such as Netfilter/iptables (see Chapter 13) blocking
access to the web server.

Creating a Simple Root-Level Page


If you like, you can start adding files to Apache right away in the /var/www/html directory for top-
level pages (for a source install, the directory would be /usr/local/httpd/htdocs). Any files placed in
that directory must be world-readable.
As mentioned earlier, Apache’s default web page is index.html. Let’s take a closer look at
creating and changing the default home page so that it reads, “Welcome to webserver.example.org.”
Here are the commands:

You could also use an editor such as vi, pico, or emacs to edit the index.html file and make it
more interesting.

You might also like