Out of the Box

Until Apache 1.3, there was no real out-of-the-box batch-capable build and installation procedure for the complete Apache package. This method is provided by a top-level configure script and a corresponding top-level Makefile.tmpl file. The goal is to provide a GNU Autoconf-style frontend that is capable of driving the old src/Configure stuff in batch.

Once you have extracted the sources (see earlier), the build process can be done in a minimum of three command lines — which is how most Unix software is built nowadays. Change yourself to root before you run ./configure; otherwise, if you use the default build configuration (which we suggest you do not), the server will be looking at port 8080 and will, confusingly, refuse requests to the default port, 80.

The result is, as you will be told during the process, probably not what you really want:

./configure
make
make install

This will build Apache and install it, but we suggest you read on before deciding to do it this way. If you do this — and then decide to do something different, do:

               make clean

afterwards, to tidy up. Don’t forget to delete the files created with:

rm -R /usr/local/apache

Readers who have done some programming will recognize that configure is a shell script that creates a Makefile. The command make uses it to check a lot of stuff, sets compiler variables, and compiles Apache. The command make install puts the numerous components in their correct places around your machine, using, in this case, the default Apache layout, which we do not particularly like. So, we recommend a slightly more elaborate procedure, which uses the GNU layout.

The GNU layout is probably the best for users who don’t have any preconcieved ideas. As Apache involves more and more third-party materials and this scheme tends to be used by more and more players, it also tends to simplify the business of bringing new packages into your installation.

A useful installation, bearing in mind what we said about modules earlier and assuming you want to use the mod_proxy DSO, is produced by:

make clean
./configure --with-layout=GNU \
    --enable-module=proxy --enable-shared=proxy
make
make install

( the \ character lets the arguments carry over to a new line). You can repeat the --enable- commands for as many shared objects as you like.

If you want to compile in hooks for all the DSOs, use:

./configure --with-layout=GNU --enable-shared=max 
make
make install

If you then repeat the ./configure... line with --show-layout > layout added on the end, you get a map of where everything is in the file layout. However, there is an nifty little gotcha here — if you use this line in the previous sequence, the --show-layout command turns off actual configuration. You don’t notice because the output is going to the file, and when you do make and make install, you are using whichever previous ./configure actually rewrote the Makefile — or if you haven’t already done a ./configure, you are building the default, old Apache-style configuration. This can be a bit puzzling. So, be sure to run this command only after completeing the installation, as it will reset the configuration file.

If everything has gone well, you should look in /usr/local/sbin to find the new executables. Use the command ls -l to see the timestamps to make sure they came from the build you have just done (it is surprisingly easy to do several different builds in a row and get the files mixed up):

total 1054
-rwxr-xr-x  1 root  wheel   22972 Dec 31 14:04 ab
-rwxr-xr-x  1 root  wheel    7061 Dec 31 14:04 apachectl
-rwxr-xr-x  1 root  wheel   20422 Dec 31 14:04 apxs
-rwxr-xr-x  1 root  wheel  409371 Dec 31 14:04 httpd
-rwxr-xr-x  1 root  wheel    7000 Dec 31 14:04 logresolve
-rw-r--r--  1 root  wheel       0 Dec 31 14:17 peter
-rwxr-xr-x  1 root  wheel    4360 Dec 31 14:04 rotatelogs

Here is the file layout (remember that this output means that no configuration was done):

Configuring for Apache, Version 1.3.26
 + using installation path layout: GNU (config.layout)

Installation paths:
               prefix: /usr/local
          exec_prefix: /usr/local
               bindir: /usr/local/bin
              sbindir: /usr/local/sbin
           libexecdir: /usr/local/libexec

               mandir: /usr/local/man
           sysconfdir: /usr/local/etc/httpd
              datadir: /usr/local/share/httpd
             iconsdir: /usr/local/share/httpd/icons
            htdocsdir: /usr/local/share/httpd/htdocs
               cgidir: /usr/local/share/httpd/cgi-bin
           includedir: /usr/local/include/httpd
        localstatedir: /usr/local/var/httpd
           runtimedir: /usr/local/var/httpd/run
           logfiledir: /usr/local/var/httpd/log
        proxycachedir: /usr/local/var/httpd/proxy

Compilation paths:
           HTTPD_ROOT: /usr/local
      SHARED_CORE_DIR: /usr/local/libexec
       DEFAULT_PIDLOG: var/httpd/run/httpd.pid
   DEFAULT_SCOREBOARD: var/httpd/run/httpd.scoreboard
     DEFAULT_LOCKFILE: var/httpd/run/httpd.lock
      DEFAULT_XFERLOG: var/httpd/log/access_log
     DEFAULT_ERRORLOG: var/httpd/log/error_log
    TYPES_CONFIG_FILE: etc/httpd/mime.types
   SERVER_CONFIG_FILE: etc/httpd/httpd.conf
   ACCESS_CONFIG_FILE: etc/httpd/access.conf
 RESOURCE_CONFIG_FILE: etc/httpd/srm.conf

Since httpd should now be on your path, you can use it to find out what happened by running it, followed by one of a number of flags. Enter httpd -h. You see the following:

httpd: illegal option -- ?
Usage: httpd [-D name] [-d directory] [-f file]
             [-C "directive"] [-c "directive"]
             [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]
Options:
  -D name          : define a name for use in <IfDefine name> directives
  -d directory     : specify an alternate initial ServerRoot
  -f file          : specify an alternate ServerConfigFile
  -C "directive"   : process directive before reading config files
  -c "directive"   : process directive after  reading config files
  -v               : show version number
  -V               : show compile settings
  -h               : list available command line options (this page)
  -l               : list compiled-in modules
  -L               : list available configuration directives
  -S               : show parsed settings (currently only vhost settings)
  -t               : run syntax check for config files (with docroot check)
  -T               : run syntax check for config files (without docroot check)

A useful flag is httpd -l, which gives a list of compiled-in modules:

Compiled-in modules:
  http_core.c
  mod_env.c
  mod_log_config.c
  mod_mime.c
  mod_negotiation.c
  mod_status.c
  mod_include.c
  mod_autoindex.c
  mod_dir.c
  mod_cgi.c
  mod_asis.c
  mod_imap.c
  mod_actions.c
  mod_userdir.c
  mod_access.c
  mod_auth.c
  mod_so.c
  mod_setenvif.c

This list is the result of a build with only one DSO: mod_alias. All the other modules are compiled in, among which we find mod_so to handle the shared object. The compiled shared objects appear in /usr/local/libexec as .so files.

You will notice that the file /usr/local/etc/httpd/httpd.conf.default has an amazing amount of information it it — an attempt, in fact, to explain the whole of Apache. Since the rest of this book is also an attempt to present the same information in an expanded and digestible form, we do not suggest that you try to read the file with any great attention. However, it has in it a useful list of the directives you will later need to invoke DSOs — if you want to use them.

In the /usr/src/apache/apache_XX directory you ought to read INSTALL and README.configure for background.