Apache Guide: Configuring Your Apache Server Installation

Apache Guide: Configuring Your Apache Server Installation


July 10, 2000

Most of your server configuration is done in the server configuration files, after you have installed Apache. However, the things that you are able to configure are largely decided when you install the server. That is, if you don't install a particular module, then you cannot configure the things that that module control.

In the configuration stage, before you compile your Apache server, you decide what modules you want installed, where you want files to get put, and a variety of other things. You can also specify various things that get set in the server configuration files, which you can then change afterwards.

In this week's column, we'll talk about some of the things that you can do with the configure utility, so that Apache gets installed exactly the way that you want it.

A Basic Installation

For a basic Apache installation, using all the default settings, simply follow the instructions that you see near the top of the README.configure file:

        tar -zxf apache_1.3.12.tar.gz
        cd apache_1.3.12
        ./configure --prefix=PREFIX
        make
        make install

And of course, even that does not accept all the defaults, because we are specifying where we want the files to be put. PREFIX is not actually the literal string PREFIX, but is the directory under which you want Apache installed, such as /usr/local/apache.

Configure Options

If you simply run configure, without providing any arguments, Apache warns you:

        Configuring for Apache, Version 1.3.12
        + Warning: Configuring Apache with default settings.
        + This is probably not what you really want.
        + Please read the README.configure and INSTALL files
        + first or at least run './configure --help' for

        + a compact summary of available options.

When we type configure --help, we get several pages of options. Many of them will not be covered in this article, but several of them are remarkably useful.

--show-layout
The --show-layout option tells you where Apache will put files when it installs. Running with this option does not actually do anything, it just figures out where everything will wind up if you did configure with the particular options you have selected. This is particularly useful when you are experimenting with various different configurations, and don't want to actually install them to see what they will end up looking like.

--sysconfdir=DIR
The --sysconfdir option lets you specify where the server configuration files will live. With a default installation, there will be a conf subdirectory under the main server root directory, which will contain these files. However, some folks like for all their configuration files of any kind to be located in /etc, and so you might want to do:

        ./configure --sysconfigdir=/etc/httpd

--htdocsdir=DIR
--htdocsdir sets the location where web documents will be stored, and served from. If, for example, you install Apache from the RPM (Red Hat Package Manager) file, you will find that the document directory is located in /home/httpd/html, while the other files are located at various other places around the system.

Other File Locations

There are also a number of directives like the last few, which let you set the location of files. --iconsdir sets the location of the icon files, --bindir and --sbindir set the locations of the binary executables, and so on.

My personal preference is to install all of Apache in one location (/usr/local/apache, to be specific) and then just make symlinks from other locations. For example, system log files are located in /var/log, so it might make sense to have the Apache log files there also. However, instead of using a --logfiledir=/var/log/httpd configuration option, I simply create a symbolic link from /var/log/httpd to /usr/local/apache/logs:


        cd /var/log
        ln -s /usr/local/apache/logs httpd

This is also handy for your log rotate scripts, which expect log files to be in /var/log and subdirectories thereof.

Module Configuration

You can tell Apache what modules to build and activate with configuration options. In a default configuration, some modules are enabled, and others are not. To change this default configuration, you can use the --enable-module and --disable-module directives.

The default configuration is as follows:

                        [access=yes      actions=yes     alias=yes      ]
                        [asis=yes        auth=yes        auth_anon=no   ]
                        [auth_db=no      auth_dbm=no     auth_digest=no ]
                        [autoindex=yes   cern_meta=no    cgi=yes        ]
                        [digest=no       dir=yes         env=yes        ]
                        [example=no      expires=no      headers=no     ]
                        [imap=yes        include=yes     info=no        ]
                        [log_agent=no    log_config=yes  log_referer=no ]
                        [mime=yes        mime_magic=no   mmap_static=no ]
                        [negotiation=yes proxy=no        rewrite=no     ]
                        [setenvif=yes    so=no           speling=no     ]
                        [status=yes      unique_id=no    userdir=yes    ]
                        [usertrack=no    vhost_alias=no                 ]

For example:

        ./configure --prefix=/home/httpd --enable-module=speling                         --disable-module=userdir

If you wish to build a particular module as a shared object you can use the --enable-shared option. For example:


        ./configure --prefix=/usr/local/apache                 --enable-module=rewrite                 --enable-shared=rewrite

To compile and enable a module that is not part of the standard Apache distribution, you can use the --add-module and --activate-module options. For example:

        ./configure --prefix=/usr/local/apache                 --add-module=/home/rbowen/mods/mod_mine.c

Manually Tweaking Your Configuration

As I mentioned in my last column, there are two ways to configure your Apache build. There's the method describe above, and then there's the "old-fashioned" manual process. In the src/ subdirectory is a script called Configure (big C), which uses a file called Configuration to configure your build. A sample Configuration file, called Configuation.tmpl, comes with Apache. And when you run configure (small c), a configuration file called Configuration.apaci is generated, and is then used by Configure (big C) to configure the build.

If you open up Configuration.apaci, you'll see the configuration options that you entered, converted into a format that is usable by Configure. You can manually change any of these options to modify the configuration, and then rerun Configure to make the makefiles again, like so:

        ./Configure -file Configuration.apaci

This is particularly useful if you want to experiment with different build configurations. Or, as in my case, if you need to support several different customers, and want to mirror their Apache installation as closely as possible. You can simply save several different versions of your Configuration file, and then rebuild using the one that you like.

The format of the Configuration files is fairly self-explanatory, and they are heavily commented, which should help you figure out what you need to do. Also, read the file INSTALL, also located in the src/ subdirectory.

For More Information

The complete resource on using configure is README.configure, which is in the top directory when you unpack the Apache source tarball. It gives you all the available commandline options, and gives a few examples of common configurations.

And for more information about Configure, read INSTALL in the src/ subdirectory.

Rich Bowen is the Director of Web Application Development at The Creative Group and the author of Apache Server Unleashed.