Professional Documents
Culture Documents
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
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.
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:
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
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
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:
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.
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:
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.
You could also use an editor such as vi, pico, or emacs to edit the index.html file and make it
more interesting.