Installing Apache from Source Code

Installing Apache by compiling the code from the source distribution is the preferred installation method because it allows you to configure the server to fit your needs. Any binary installation that you download will have someone else’s configuration, which you may not be able to alter to suit your needs.

For example, if you download and install a binary that has CGI support, you may have to live with the CGI support even if you never run CGI programs. If the CGI module is configured as a dynamically shared module, then you can disable it very easily; however, if the support is statically built into a binary, then you’ll just have to live with CGI.

If you compile a lean and mean Apache server from the source distribution, however, you get the components that you need with no wasted processes or disk space. The Apache source distribution comes with a script called configure that allows you to configure the source tree before you compile and install the binaries.

From the Apache source distribution directory, you can run this script as follows:

./configure --prefix=apache_installation_dir

The --prefix option tells Apache to install the binaries and other necessary configuration and support files in apache_installation_dir. For example:

./configure --prefix=/usr/local/apache

Here Apache source will be configured so that all the binaries and supporting files will be installed in the /usr/local/apache directory. There are many options that you can use with the configure script. Most of these options are not required for most sites.

Typically, all you need is to specify the --prefix option and any options to enable or disable one or more modules. For example, say you do not want to install the CGI module on your system. You can run the configure script using the --disable-cgi --disable-cgid options to disable CGI support.

Similarly, to disable the Server-Side Include (SSI) support you can use the --disable-include option. After you have configured Apache using the configure script, you can use the config.status script instead of configure for any subsequent configuration needs.

By using the config.status script, you can reuse your previous configuration and add or subtract new options. For example, say you configured Apache with the following command line:

./configure --prefix=/usr/local/apache --disable-cgi --disable-cgid

and a few days later decided to disable SSI. You can now use:

./config.status --disable-include

When you recompile Apache, the CGI modules will still not be included, because ./config.status stores the options that you specified using the configure script earlier. If you wish to start fresh, use configure every time.

If you run Apache on a extremely busy server where hundreds of requests per second is a requirement, you might have to change the default hard limits set in the MPM module of your choice.

The hard limits that you want to consider changing are the default HARD_SERVER_LIMIT and HARD_THREAD_LIMIT. The HARD_SERVER_LIMIT sets the maximum number of child servers Apache can spawn. The HARD_THREAD_LIMIT sets the total number of threads Apache can create within all of its children.

Also note that the MaxClients directive sets the limit on the number of child processes that will be created to serve requests. When the server is built without threading, no more than this number of clients can be served simultaneously.

To configure more than 256 clients, you must edit the HARD_SERVER_LIMIT entry in mpm_default.h and recompile. After you have configured the Apache source using the configure script you need to follow these steps to compile and install Apache:

  1. Run the make command to compile the source.
  2. Run the make install command to install the httpd and support files in the directory you specified using the --prefix option.
  3. Change to the installation directory and browse the directory. You should see subdirectories such bin cgi-bin, conf, htdocs, icons, include, lib, and logs. For example, if you use --prefix=/usr/local/apache with the configure script during source tree configuration, make install will create the following directory structure:

/usr/local/apache | +---include +---lib +---bin +---conf +---htdocs | | | +--manual | | | +--developer | +--howto | +--images | +--misc | +--mod | +--platform | +--programs | +--search | +--vhosts | +---icons | | | +---small | +---logs +---cgi-bin

You can download the Apache binaries appropriate for your system from www. apache.org/dist/httpd/binaries directory. Download the latest version and extract the compressed file into a temporary directory.

To determine how to install the binaries in your specific platform, you must read the INSTALL.bindist file, which is included in each binary distribution. If you wish to install the Apache RPM (Red Hat Package Management) package for your Linux system, then do the following:

  1. Go to the rpmfind.net and search for the string Apache to locate the Apache RPM packages. From the search result locate the latest version of the binary Apache RPM distribution and download it.
  2. As root, run rpm -ivh apache_rpm_package.rpm command to install the package. For example, to install the apache-2.0.4-i386.rpm for a Red Hat Linux (Intel) system, run the rpm -ivh apache-2.0.4-i386.rpm command.

Do you ever wonder whether, by the time you get around to installing the downloaded Apache source or binaries, a new version is out or perhaps a security patch is available? Software changes very quickly these days, and there’s always one update after another—which is good, but not always easy to keep up with if you have a real job to do.

There are two Apache resources that you should take advantage of immediately.

  • ApacheToday—This is the best Apache news site in the world. You can get all the Apache news you want. By using its Your Apache Today feature, you can filter news contents and get just want interests you the most. You can also take advantage of triggers that pushes breaking news that you do not want to miss.
  • ApacheWeek—Just subscribe (for free) to the great Apache resource called Apache Week, and all the Apache news will be e-mailed directly to you. This is a great information resource for Apache administrators who want to be on top of Apache development news. You can also read many helpful articles on how to get the best out of your server. I highly recommend checking out this Web site.