Chapter 15. Apache 197
15.4. Adding Modules to Your Server
Since Apache 1.3 supports DSOs, you can easily load Apache modules or compile in your own mod-
ules to your Web server. DSO support means that modules may be loaded at runtime. Since the mod-
ules are only loaded as necessary, they will not use any memory unless they are loaded.
The Apache Group provides complete DSO Documentation at http://httpd.apache.org/docs/dso.html.
After installation of your server, you can also check http://localhost/manual/mod/ for documentation
on Apache modules in HTML format, if you installed the apache-manual package.
For Apache to use a dynamically shared module, that module must have a LoadModule line and an
AddModule line in httpd.conf. By default, many modules have these two lines already included in
httpd.conf, but a few of the less commonly used modules are commented out. The commented out
modules were included during compilation, but they are not loaded by default.
If you need to use one of those non-loaded modules, look in the httpd.conf file to see all the
available modules. Each of the available modules has a corresponding LoadModule line. To show
you an example, the LoadModule section begins with these seven lines:
#LoadModule mmap_static_module modules/mod_mmap_static.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule env_module modules/mod_env.so
LoadModule config_log_module modules/mod_log_config.so
LoadModule agent_log_module modules/mod_log_agent.so
LoadModule referer_log_module modules/mod_log_referer.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
Most of the lines are not commented out, indicating that each associated module was compiled in and
is loaded in by default. The first line is commented out, which means that the corresponding module,
mmap_static_module, was compiled in but not loaded.
To make Apache load an unloaded module, first uncomment the corresponding LoadModule line. For
example, if you wanted to make Apache load in the mime_magic_module, uncomment this line:
#LoadModule mime_magic_module modules/mod_mime_magic.so
Next, you need to uncomment the corresponding line from the AddModule section in httpd.conf.
To continue with our previous example, uncomment the mod_mime_magic line, which looks like the
following:
#AddModule mod_mime_magic.c
Once you have uncommented the LoadModule and AddModule lines for the module that you want
to reload or restart Apache, as covered in Section 15.2. After restarting, the module should load.
If you have your own module, you can add it to the httpd.conf file so that it is compiled in and
loaded as a DSO. You need the apache-devel package because it installs the include files, the header
files and the APache eXtenSion (APXS) support tool. APXS uses the include files and the header files
to compile your module so that it will work with Apache.
If you have written your own module or are using a third party module, you should be able to use
APXS to compile your module sources outside the Apache source tree, without needing to tweak any
compiler or linker flags. If you need more information on APXS, please see the Apache documentation
at http://httpd.apache.org/docs/dso.html.
Once you have compiled your module using APXS, put your module in the /usr/lib/apache/ di-
rectory. Then your module needs both a LoadModule line and an AddModule line in the httpd.conf
file. After the LoadModule list in httpd.conf, add a line for the shared object file for your module
like the following:
LoadModule foo_module modules/mod_foo.so
Commenti su questo manuale