Previous Section  < Day Day Up >  Next Section

Recipe 22.2. Installing Apache 2.0 from Sources

22.2.1 Problem

You want to install Apache 2.0 from sources, so that you can customize it exactly the way you want. That means you need to know the configure options, and what modules are available. You also want to take advantage of DSOs (Dynamic Shared Objects), so you can add or remove modules later without having to recompile the httpd binary.

22.2.2 Solution

Apache 2.0 installs via the usual configure-make-make install routine. However, it has a large of number of compile-time options, so you'll spend some time selecting the ones you want. You'll also need to know the defaults. The configuration below shows a typical installation.

First, download and unpack the Apache tarball. (The current stable version is httpd-2.0.50.)

Next, make a list of all the files on your system:

# find / | grep -v -e ^/proc/ -e ^/tmp/ -e ^/dev/ > apache2-preinstall.list

You'll also make a post-install list, so you can diff the two lists and see exactly what files Apache installed.

Change to the directory where you unpacked the tarball, and display all the configuration options:

# ./configure —help | less

The default is to put everything in /usr/local/apache2. This configuration puts things in more standard locations, and modifies the default modules slightly:

#./configure —prefix=/etc/httpd \

—exec-prefix=/usr \

—bindir=/usr/bin \

—sbindir=/usr/sbin \

—mandir=/usr/share/man \

—sysconfdir=/etc/httpd/conf \

—includedir=/usr/include/httpd \

—libexecdir=/usr/lib/httpd/modules \

—datadir=/var/www/ \

—with-mpm=prefork \

—enable-mods-shared="rewrite" \

—disable-cgi

Now run make and make install:

# make

# make install

Then make another list after installation:

# find / | grep -v -e ^/proc/ -e ^/tmp/ -e ^/dev/ > apache2-postinstall.list

Now start up Apache:

# apachectl start

And open the default web page by entering http://localhost in your browser. It should look like Figure 22-1.

Figure 22-1. Default Apache web page


You now have a working web server.

22.2.3 Discussion

If you don't want to add any DSOs during configuration, but you want to enable DSO capability for adding modules later, use this line in ./configure:

--enable-so

There is no downside, except using more disk space, to building all available modules at installation. Adding or removing them is then as simple as editing httpd.conf, then restarting Apache (see the next recipe). To build all modules at compile time, do this:

--enable-mods-shared=all

There are many RPMs and .debs for Apache, so you may install from packages if you prefer. A rather large problem you will encounter is that the various package maintainers use all kinds of different filenames and have their own ideas as to where Apache's files should go. This isn't too awful if your Linux distribution provides good documentation, like Red Hat and SuSE do. But if you don't have good localized documentation, you're going to spend a fair amount of time just trying to find things.

If you run ./configure again with new settings, be sure to run make clean first, or your old configs will still be hanging around, getting in the way.

The above configuration does these things:


—prefix=/etc/httpd
—exec-prefix=/usr

These set the default installation directories. Documentation and configuration files go into the Apache default directories in /etc/httpd, and executables go in /usr, if you do not specify a different path. This recipe specifies paths for all installation directories; it sets the defaults as a safety net to catch anything that might get missed.


—bindir=/usr/bin
—sbindir=/usr/sbin
—mandir=/usr/share/man
—sysconfdir=/etc/httpd/conf
—includedir=/usr/include/httpd
—libexecdir=/usr/lib/httpd/modules
—datadir=/var/www/

Because Apache defaults to /usr/local/apache2 for everything, man pages and executables won't be in your existing Path. This example puts everything in the usual Linux places. However, stuffing everything under /usr/local/apache2 makes it simple to delete the whole works and start over, which might be useful for testing.


—with-mpm=prefork

This chapter's "Introduction" describes the three Apache threading/process models: Prefork, Worker, and PerChild. Prefork is similar to the traditional Apache 1.3 model. This is the default, and it is the safe, conservative choice. You'll still get the benefit of the many improvements in Apache 2.0. The Worker and PerChild MPMs are for high-demand servers, and are still somewhat experimental.


—enable-mods-shared="rewrite"

When you use enable-mods-shared, DSO capability is automatically included. This builds the module rewrite as a DSO instead of building it statically into the httpd binary. rewrite lets you set up URL redirects; for example, when you overhaul a web site and want to set up automatic redirections from old URLs to new ones. DSOs need a LoadModule directive in httpd.conf; rewrite looks like this:

LoadModule rewrite_module /usr/lib/httpd/modules/mod_rewrite.so


—disable-cgi

This server won't be running scripts, so it doesn't need CGI.

22.2.4 See Also

    Previous Section  < Day Day Up >  Next Section