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