Thursday, July 23, 2009

Enable apache modules under Debian based system

Apache is usually suitable out of the box for most common used. The apache structure under debian based systems is actually really well made as it is really easy to activate or deactivate module.

This how-to will show how to activate or deactivate available modules under a debian system running apache2.

1. How it works:

There is 2 kinds of modules used by apache:

  • Modules compiled in
  • Modules that are loaded when you launch apache

In order to check which modules were compiled in with apache, you can type the following command:

$apache2 -l

---------------
Compiled in modules:
core.c
mod_access.c
mod_auth.c
mod_log_config.c
mod_logio.c
mod_env.c
mod_setenvif.c
prefork.c
http_core.c
mod_mime.c
mod_status.c
mod_autoindex.c
mod_negotiation.c
mod_dir.c
mod_alias.c
mod_so.c

---------------

This list correspond to the modules compile with apache on an Ubuntu Dapper system. As you can see, there is no php, rewrite.... modules compiled in. Those modules are meant to be included when running apache.

Now, let check the main apache configuration file, namely /etc/apache2/apache2.conf, around line 115, you can see those 2 lines:

---------------
# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
---------------

As you can see, apache load any files ending with .load first and .conf after, in /etc/apache2/mods-enabled/.

Now, let's have a look in that directory:

$ ls /etc/apache2/mods-enabled/

---------------
actions.load php5.conf rewrite.load userdir.load
cgi.load php5.load userdir.conf

---------------

As you can see, I have cgi, actions, php5, userdir and rewrite modules enabled. This allow me to run an php5 scripts in /home/user/public_html using rewriting rules.

Going further up into the investigation, we can see that files in mods-enabled are not actually files, but links to files contained in mods-available:

$ ls -l /etc/apache2/mods-enabled/userdir.load

---------------
lrwxrwxrwx 1 root root 30 2006-05-15 03:00 /etc/apache2/mods-enabled/userdir.load -> ../mods-available/userdir.load

---------------

Now, let's have a look at /etc/apache2/mods-available:

$ ls /etc/apache2/mods-available/

---------------
actions.load dav_fs.conf info.load proxy.load
asis.load dav_fs.load ldap.load rewrite.load
auth_anon.load dav.load mem_cache.load speling.load
auth_dbm.load deflate.load mime_magic.conf ssl.conf
auth_digest.load disk_cache.load mime_magic.load ssl.load
auth_ldap.load expires.load php5.conf suexec.load
cache.load ext_filter.load php5.load unique_id.load
cern_meta.load file_cache.load proxy.conf userdir.conf
cgid.conf headers.load proxy_connect.load userdir.load
cgid.load imap.load proxy_ftp.load usertrack.load
cgi.load include.load proxy_http.load vhost_alias.load

---------------

This basically contains all the files linked by mods-enabled plus a whole load of available modules.

2. Adding modules:

Now, taking into account the strucutre of apache, it is pretty easy to add modules to be loaded by apache. Let's assume that you want to add mime_magic module. To do so, you can either:

  • add it by hand:

    $cd /etc/apache2/mods-enabled
    $ sudo ln -s ../mods-available/mime_magic.conf mime_magic.conf
    $sudo ln -s ../mods-available/mime_magic.load mime_magic.load

    OR

  • add it the debian way with a2enmod:

    $sudo a2enmod

  • Which module would you like to enable?
    Your choices are: actions asis auth_anon auth_dbm auth_digest auth_ldap cache cern_meta cgid cgi dav_fs dav deflate disk_cache expires ext_filter file_cache headers imap include info ldap mem_cache mime_magic php5 proxy_connect proxy_ftp proxy_http proxy rewrite speling ssl suexec unique_id userdir usertrack vhost_alias
    Module name? mime_magic
    Module mime_magic installed; run /etc/init.d/apache2 force-reload to enable.


That's it, your module will now be loaded next time you start apache. You can actually avoid restarting apache, by asking it to simply reload its configuration:

$ sudo /etc/init.d/apache2 reload

And here you go, your new added module is included in apache.

No comments:

Post a Comment

tag ur valuable ideas below