Home arrow Apache arrow Page 12 - Building Apache the Way You Want It

Configuring the Build Environment - Apache

Have you ever wanted to customize Apache? This article will help you get started on building a customized version of Apache to suit your own needs. It is taken from chapter three of the book Pro Apache third edition, written by Peter Wainwright (Apress, 2004; ISBN: 1590593006).

TABLE OF CONTENTS:
  1. Building Apache the Way You Want It
  2. Building Apache from Source
  3. General Options
  4. Enabling or Disabling Modules in Bulk
  5. Changing the Module Order (Apache 1.3)
  6. Building Apache from Source As an RPM (Apache 2)
  7. Advanced Configuration
  8. Determining Apacheís Locations Individually
  9. Choosing a MultiProcessing Module (Apache 2)
  10. Building Apache with suExec support
  11. Configuring Apache 2 for Cross-Platform Builds
  12. Configuring the Build Environment
  13. Building Modules with apxs
By: Apress Publishing
Rating: starstarstarstarstar / 14
August 18, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Some of the more obscure Apache settings arenít configurable via configure because theyíre rarely needed except for very finely tuned servers or to enable experimental features that are otherwise disabled. If you need to enable one of these special options, then you have to define themóeither in the environment before running configure or afterward in one of the EXTRA_ definitions contained in the following:

[1.3] src/Configuration.apaci
[2.0] config_vars.mk

The first route is by far the more preferable because rerunning configure will wipe out any changes you made to the files it generates.

As a practical example, one parameter you might want to set that isnít available as a configurable option is to increase the hard process limit that forms the upper boundary of the MaxClients directive. To set this so configure sees and absorbs it, add it to the environment with this:

$ CFLAGS='-DHARD_SERVER_LIMIT=1024' ./configure ...

This is just one of several values related to process and thread management that you can set at compile time; see the MPM discussion in Chapters 8 and 9 and Online Appendix J for more. For developers, one other value of note is GPROF, which creates a profiling Apache binary whose output can be analyzed with the gprof tool. It also enables an additional directive called GprofDir that determines the directory where the profile data file is created.

configure will take an environment variable and integrate it with the other compiler flags so that itís active during compilation. The distinction is actually fairly arbitrary, and in fact either will work fine.

You can even override the compiler thatís used to carry out the build; you saw an example of that earlier when I discussed cross-compiling Apache.

As another example, Apache 2 provides the experimental mod_charset_lite module for on-the-fly character set conversion. This module wonít work unless you also define APACHE_XLATE, so to enable it as well as increase the hard server limit, modify the previous command to get this:

[2.0] $ CFLAGS="-DHARD_SERVER_LIMIT=1024
-DAPACHE_XLATE" ./configure ...

Note the quotes, which are necessary if you want to specify more than one option this way.

You can also undefine something with -U if you want to undo a previously established setting. This works just the same as -D except, of course, you donít supply a value. Undefining something that isnít defined in the first place has no useful effect but is harmless.

Environment variables specified this way only last as long as the execution of the command that follows them. If youíre going to be reconfiguring Apache several times to refine the configuration, you can instead set the variable permanently (or at least for the lifetime of the shell). How you do this depends on the shell youíre using:

csh style:
$ setenv CFLAGS '-DHARD_SERVER_LIMIT=1024'
ksh/bash style:
$ export CFLAGS='-DHARD_SERVER_LIMIT=1024'

As I mentioned at the start, if youíve already run configure, you can avoid rerunning it by editing the EXTRA_CFLAGS line in this:

[1.3] src/Configuration.apaci
[2.0] config_vars.mk

But keep in mind that rerunning configure will wipe out these edits.

Building Modules with configure and apxs

Apacheís standard configuration script enables modules to be included or excluded in a flexible manner but only knows about modules that are supplied with Apache. To build third-party modules into Apache, you have to tell the configure script about them.

Itís tedious to have to reconfigure and rebuild Apache to add a dynamic module to it because you only actually want to build the module and not the entire server. For this reason, Apache comes with the apxs utility, a Perl script designed to configure and compile third-party modules without the need to have Apacheís source code present.

So Apache presents you with three options to add new modules to the server:

  • Add a new module to the Apache source tree and tell configure to use it.

  • Place the module source code somewhere in the file system and tell configure where to find it.

  • Use apxs to build the module as a dynamic loadable module independently from configure.

However, configure only works for modules that have their source code contained in a single file. More complex modules require additional steps that have their own installation scripts. These tend to use apxs to build themselves because apxs is configured with the installation information for the version of Apache that created it and can handle more than one source file. In general, if a module comes with its own configuration script, you should use it rather than try to handle the module with configure.

Itís not possible to use apxs in all situations. Very occasionally, a module may require patches to be made to the Apache source code itself before it can be built, dynamically or otherwise. To use these modules, you must therefore rebuild Apache after applying the necessary patches; apxs on its own will not be enough. Luckily, this  is a rare occurrence.

Adding Third-Party Modules with configure

The configure script allows extra modules to be incorporated into the build process with the use of two additional options, --activate-module and --add-module. In Apache 2, --activate-module has been replaced by the semantically similar --with-module.

For example, to include the third-party module mod_bandwidth into Apache 1.3 as a static module, you first copy the source file mod_bandwidth.c into the /src/modules/extra directory and then tell configure to use it with this:

[1.3] $ ./configure --activate-module=src/modules/extra/ mod_bandwidth.c

You have to specify a relative pathname to the file that starts with src/modules in Apache 1.3; configure will not automatically realize where to find itóin this case, you have put the code in the extra directory, which exists in the Apache 1.3 source tree for just this purpose.

In Apache 2, the source distribution is organized a little differently, with a top-level modules directory under which modules are subcategorized by type: filters, generators, loggers, and so on. Thereís no extra directory as standard, but you can easily create one and then include a third-party module by copying the module source and activating it with this:

[2.0] $ ./configure --with-module=extra:mod_bandwidth.c

Many third-party modules provide their own installation scripts. This is typically the case where the module involves multiple source files and canít be built using Apacheís default module compilation rules. These typically build the module and then copy it into the Apache modules directory tree ready for Apache to link them. Accordingly, both --activate-module and --with-module will also accept an object file  or a shared library object as the file parameter, for example:

[2.0] $ ./configure --with-module=extra:mod_bandwidth.o

You donít have to stick with an extra in Apache 2; you can as easily create a mymodules directory if you prefer. On Unix systems, you can also use a symbolic link to point to a directory outside the distribution.

If configure finds the source code for the module, Apache 1.3 will print out an opening dialogue such as the following:

Configuring for Apache, Version 1.3.28
+ using installation path layout: Apache (config.layout)
+ activated bandwidth module (modules/extra/ mod_bandwidth.c)

Apache 2 will report the extra module in the report of enabled modules:

checking for extra modules... added extra:mod_bandwidth.c

Itís worth watching for these messages; if configure fails to find the module, this is when it will tell you.

To compile the module as a shared (dynamic) module, instead you can use --enable-shared:

[1.3] $ ./configure --activate-module=src/modules/ extra/mod_bandwidth.c
      --enable-shared=bandwidth
[2.0] $ ./configure --with-module=extra:mod_bandwidth.c
      --enable-mods-shared=bandwidth, <other modules>

Or, alternatively, to make all modules shared, including extras:

[1.3] $ ./configure --activate-module=src/modules/extra/ mod_bandwidth.c
      --enable-shared=max
[2.0] $ ./configure --with-module=extra:mod_bandwidth.c
      --enable-mods-shared=all

Rather than spending time copying module source code, you can have configure do it for you with the --add-module option. This has the same effect as --activate-module, but first copies the source code for the module from the specified location into src/modules/extra before activating it:

[1.3] $ ./configure --add-module=~/apache-modules/mod_bandwidth/mod_bandwidth.c

This produces a slightly different dialogue:

Configuring for Apache, Version 1.3.28
 
+ using installation path layout: Apache (config.layout)
 + on-the-fly added and activated bandwidth module (modules/extra/mod_bandwidth.o)

Once the module has been added, it can subsequently be configured with --activate-module because the source code is now within the Apache source tree. Itís not necessary to keep copying in the source code with --add-module.



 
 
>>> More Apache Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

APACHE ARTICLES

- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: