There are about as many ways to build and install Apache as there are reasons to run a web server. As it's our first time out, we'll take the road most traveled and leave the advanced configurations for later columns.
In this column, I'll wander through three methods of Apache installation under Unix:
I find installing Apache from scratch the simplest and most flexible method, but I'll leave you to choose which method you prefer.
(This article does not cover Apache Win 32. If you wish to install Apache under Windows 95, 98, or NT, take a look at Apache.org's excellent step-by-step tutorial at: http://www.apache.org/docs/windows.html.)
You can download Apache from the Apache Software Foundation web site, in source and binary forms. While you're there, you may want to browse the Announcement and CHANGES files.
To install Apache, you'll need:
tar
and gunzip Unix utilities
A binary is pre-fab, which means someone else has gone to the trouble of configuring and building the software for you. There are, however, a few caveats I should mention:
Now let's
install a binary. Point your browser at
http://www.apache.org/dist/binaries
and download the binary for your operating system. You'll most
likely be presented with a directory containing multiple
versions of Apache in various compressed forms. For the
purposes of this tutorial, I'll assume you've downloaded the
gzip'd form of the latest 1.3.x Apache binary (currently that's
apache_1.3.9-i386-whatever-freebsd3.2.tar.gz on my FreeBSD
box). If there is a ReadMe associated with the file you're
downloading, you may want to review it for any interesting
installation tidbits or possible bugs.
If you can't find a binary for your operating system, choose either the "From Scratch" or "Using an RPM" (if you are running Red Hat Linux) method.
Now let's uncompress the archive using the handy combination of gunzip and tar. You should replace the "apache_1.3.9-i386-whatever-freebsd3.2.tar.gz" text below with
the name of the gzip'd file you downloaded.
gunzip < apache_1.3.9-i386-whatever-freebsd3.2.tar.gz | tar xvf -
Some of you may be lucky enough to have a version of tar that is capable of
taking care of both tasks.
tar xvzf apache_1.3.9-i386-whatever-freebsd3.2.tar.gz
Either way, you should end up with an apache_1.3.x directory, with x being the particular sub-version of Apache you downloaded. Move into
the newly created directory.
cd apache_1.3.x
As of Apache 1.3.11, binary distributions contain an install script;
mine's called install.bindist.sh. If your binary does
not seem to contain such an install script, take a look at the
README.bindist and/or INSTALL.bindist documents for further information;
if these documents don't outline a simple installation
method, you'll probably want to use one of the other
methods I cover in this column.
If you've not already done so, you'll need to become root. Then go ahead and run the install script.
./install.bindist.sh
This command should install the various bits of the Apache
distribution into the appropriate locations; the default is usually to
install everything under /usr/local/apache (confirm this
by consulting your README.bindist and/or INSTALL.bindist documents).
That's it for installing binaries. If you're interested in learning how to install Apache using Red Hat Package Manager or from scratch, read on. Or, if you're just using the binary section of this tutorial, you can skip ahead to Starting Apache.
Getting, Installing, and Running Apache
by Rael Dornfest |
Those of you running the RedHat Linux distribution may want to take advantage of RedHat's RPM ("RedHat Package Manager") system. Almost identical to a binary, an RPM is further customized to play nicely with other RPMs and provide a consistent interface to installing, updating, and removing binaries. I admit I'm not a great fan of packaged binaries. They often entail a loss of flexibility and clarity -- for instance, it's not readily apparent where the contents of some packages will end up. That said, for Linux newcomers or when installing a small standard component, RPMs are simple and reliable.
Bear in mind that an Apache RPM may already be installed on your system depending on how Linux was originally installed on your computer. To find out, at the shell prompt, type:
rpm -qa | grep apache
If you see something like apache-1.3.9xxx, an
Apache RPM has already been installed and you can skip on to
"Starting Apache".
If you don't have an Apache RPM, you must obtain one. RedHat 6.1 ships with
apache-1.3.9-4.i386.rpm in the RedHat/RPMS
directory on the installation CD. Or, point your Web browser at
ftp://ftp.redhat.com/pub/redhat/current/i386/RedHat/RPMS
or one of the many
mirror sites
and pick yourself up a copy. If you've not already done so, you'll
need to become root. Navigate to the same directory as the .rpm file
you obtained, and then type the following command, substituting the
name of the .rpm you're using for apache-1.3.9-4.i386.rpm.
rpm -ivh apache-1.3.9-4.i386.rpm
RPM should grind away, displaying its progress with a primitive #######
progress bar. Barring any errors, you're done.
If you're interested in learning how to install Apache from scratch, read on. Or, if you're just using the RPM section of this tutorial, you can skip on to Starting Apache.
Getting, Installing, and Running Apache
by Rael Dornfest |
Building Apache from source may seem a daunting proposition to newcomers, but the Apache developers have done a wonderful job of making the task about as simple as could be. Just three more commands than a binary installation and you skip the arduous task of figuring out which binary is the right one for your particular operating system. Let's give it a whirl, shall we?
Point your Web browser at http://www.apache.org/dist and download the gzip'd form of the current version of Apache (1.3.11 at the time of this writing).
Now let's uncompress that archive using gunzip and tar. You should
replace the apache_1.3.11.tar.gz below with the name of
the gzip'd file you downloaded.
gunzip < apache_1.3.11.tar.gz | tar xvf -
You should end up with an apache_1.3.x directory, x being
the particular sub-version of Apache you downloaded. Move into the
newly created directory.
cd apache_1.3.x
Now we'll use the the configure and make
commands to (you guessed it) configure, make, and install Apache. If you've
not already done so, now would be the time to become root.
./configure
Your screen should look something like:
# ./configure
Configuring for Apache, Version 1.3.11
...
Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
+ configured for Linux platform
+ setting C compiler to gcc
+ setting C pre-processor to gcc -E
+ checking for system header files
+ adding selected modules
+ checking sizeof various data types
+ doing sanity check on compiler and options
...
Creating Makefile in src/modules/standard
Unless errors were reported (not warnings, mind you), your Apache
installation is now configured and we can move on. This is where things
get a bit ugly -- not difficult, mind you, only ugly. Make'ing Apache
produces screenfulls of scary-looking output, but don't worry -- as long
as the process doesn't stop suddenly with an error message, all is as
it should be.
make
Your screen should look something like:
#Finally, you're ready to install your Apache build.make===> src make[1]: Entering directory `src/httpd/apache_1.3.11' make[2]: Entering directory `src/httpd/apache_1.3.11/src' ===> src/regex ... [several lines later] ... gcc -DLINUX=2 -DUSE_HSREGEX -DUSE_EXPAT -I../lib/expat-lite
-DNO_DL_NEEDED `../apaci` -o ab -L../os/unix
-L../ap ab.o -lap -los -lm -lcrypt
make[2]: Leaving directory `src/httpd/apache_1.3.11/src/support' <=== src/support
make[1]: Leaving directory `src/httpd/apache_1.3.11' <=== src #
# make install
And you're done! Pretty painless, you have to admit -- although the
make output can bring about mild eye-strain ;-)
Let's take your new Apache installation out for a spin.
/usr/local/apache/bin/apachectl start
httpd
Point your browser at your brand new Web server,
http://hostname, substituting your server's hostname
for hostname and you should see the magnificent "It worked!"
default home page.
Configuring Apache
Of course, if you'd like me to cover anything in particular, feel free to post your suggestions to the O'Reilly Network Apache Forum.
Copyright © 2009 O'Reilly Media, Inc.