Managing Apache2 modules the Debian way
The Apache2 HTTP Server is a modular program, where we can choose its functionality by including in the server a set of modules. The modules can be statically compiled into the httpd binary when the server is built. Alternatively, modules can be compiled as Dynamic Shared Objects (DSOs) that exist separately from the main httpd binary file.
Normally enabling one particular apache DSO module will involve editing the main apache configuration file and adding a LoadModule line to enable the loading of the particular module. Depending from the module itself, we might need to add also some configuration directives. This will work fine on Debian also, but I am going to show you the Debian particular method of managing apache2 modules.
Regardless of the apache MPM (Multi-Processing Modules) you are using: apache2-mpm-prefork, apache2-mpm-worker or apache2-mpm-perchild after the installation you will end up with some default modules: some already enabled and some ready to be used. Opposed to a RedHat based system for example (where they will try to enable all the possible modules) the Debian package will enable by default only a very small amount of modules.
Here are the modules enabled by default:
Compiled statically inside the apache2 binary: core, http_core, prefork/worker/perchild, mod_access, mod_auth, mod_log_config, mod_logio, mod_env, mod_setenvif, mod_mime, mod_status, mod_autoindex, mod_negotiation, mod_dir, mod_alias, mod_so.
- You can get the list of compiled in modules from the command line with, apache2 -l
- These modules can’t be disabled without recompiling the apache package
- For more details on the build-in modules you can check Appendix 1.
Standard apache2 modules installed and ready to be enabled: actions, asis, auth_anon, auth_dbm, auth_digest, auth_ldap, cache, cern_meta, cgi, cgid, dav, dav_fs, deflate, disk_cache, expires, ext_filter, file_cache, headers, imap, include, info, ldap, mem_cache, mime_magic, proxy, proxy_connect, proxy_ftp, proxy_http, rewrite, speling, ssl, suexec, unique_id, userdir, usertrack, vhost_alias.
- only one module is enabled by default: mod_userdir
- You can enable any of these modules at any time with as shown bellow.
- For more details on the standard modules installed you can check Appendix 2.
Other apache2 modules available: you can install additional apache2 modules that are not standard if needed. Probably you will like to have php installed that way, but maybe some others based on the particular need. The installation uses the regular apt commands, for example:
aptitude install libapache2-mod-php4
The list of additional modules that can be installed includes: mod-geoip, mod-jk, mod-mono, mod-perl2,mod-php4, mod-php5, mod-python, mod-rpaf, mod-ruby, mod-suphp.
- For the full list of extra modules available you can check Appendix 3.
- Normally when you install one of the extra modules the debian package will automatically enable it. If needed, you can disable it as shown bellow (if you don’t want to completely remove it).
Managing apache2 modules in Debian:
The Debian apache2 package provides a unique mode of managing modules. All the loading and configuration related entries are found in individual files inside folder /etc/apache2/mods-available/. Here we will find files like module_name.load (and if needed module_name.conf). Also all additional installed modules will place their configuration files in the same place.
Inside the folder /etc/apache2/mods-enabled/ we will find all the enabled modules. Here we will find symlinks to the files from mods_available for all the enabled modules. Only the modules found in this folder will be enabled at run time.
For example the configuration file for mod_rewrite includes only one line to load the module:
cat /etc/apache2/mods-enabled/rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
So in order to enable one additional module we will only have to create the proper symlinks from the mods-available to the mod-enabled files… But why not use the little tools Debian provides us for this:
- a2enmod: enables an apache2 module (this does nothing else but creates the proper links to the module .load and .conf files). For example to enable the rewrite module:
a2enmod rewrite - a2dismod: disables an apache2 module (removes the links from mod-enabled for the module). For example to disable the rewrite module:
a2dismod rewrite
Running a2enmod without any parameter will show the possible choices:
a2enmod
Which module would you like to enable?
Your choices are: actions asis auth_anon auth_dbm auth_digest auth_ldap cache cern_meta cgi cgid dav dav_fs deflate disk_cache expires ext_filter file_cache geoip headers imap include info ldap mem_cache mime_magic php4 proxy proxy_connect proxy_ftp proxy_http rewrite rpaf ruby speling ssl suexec unique_id userdir usertrack vhost_alias
Module name?
Running a2dismod without any parameter again will show us the list of enabled modules and allow to choose one:
a2dismod
Which module would you like to disable?
Your choices are: actions cgi deflate geoip headers info php4 rewrite rpaf ruby
Module name?
Don’t forget to reload the apache daemon, after making any changes to the list of enabled modules:
/etc/init.d/apache2 reload >







1st June 2006, 08:13
I manage more than 10 Apache servers for one of my customers, and each server needs different modules. I personally feel that Debian’s way of enabling/disabling Apache modules is by far the smartest in the mainline distributions.
Also, Debian uses the very same concept when enabling/disabling virtualhosts, using a2ensite and a2dissite scripts.
1st June 2006, 18:16
[...] Managing Apache2 modules the Debian way | MDLog:/sysadmin (tags: apache linux debian) [...]
2nd June 2006, 01:54
one little change to this would be to reload the web server using: apache2ctl graceful
8th July 2006, 09:53
This is a cracking/fantastic approach. The easiest and most sultry I’ve come across.
Keep up the good work
Ian
1st May 2007, 04:42
hi,
great post,
I have a little question, why cant we install php4 and php5 module in the same time?
can’t we hack this by making a script that switching between this 2 versions ?
thanks
1st May 2007, 07:53
paradox,
You can install one of them as CGI and the other one as regular apache module and have special rules (like *.php5 or per vhost) to use both of them simultaneously. I have a post about this in my drafts and as soon as I’ll have some time I’ll finish it and post it to the site.
hth,
- Marius -
13th September 2008, 04:31
[...] - module loading (for more details on module handling on Debian you might check this post: Managing Apache2 Modules the Debian Way): /etc/apache2/mods-enabled/*.load /etc/apache2/mods-enabled/*.conf - vhosts loading: [...]
14th September 2008, 22:24
[...] Nous pourrions… mais Debian et Ubuntu ont une méthode plus facile pour gérer les modules disponibles. [...]
17th November 2008, 20:53
[...] useful resources for webserver on linux http://www.ducea.com/2006/05/30/managing-apache2-modules-the-debian-way/ [...]