Example : How To Add New Modules In Apache

January 31, 2012 | By
| Reply More

Apache Linux


The Apache web server is a modular program. We can dynamically add and remove modules without recompiling the whole program. The modules in apache are known as Dynamic Shared Objects (DSOs). An example of commonly used module is mod_perl, which is used to increase Perl CGI script execution speed by embedding Perl interpreter in the running httpd process. This article shows how we can add or remove these modules from Apache.

Building Modules

You can build your own third party modules using the Apache Extension Tool "apxs" (APache eXtenSion). Suppose you have a third party module named "raghu.c" to be used in Apache. Now, first we need to compile this module using:

$ apxs -c raghu.c

The -c option will compile the module for you and create a file named "mod_raghu.so". After compilation has been completed successfully, run the following command:

$ apxs -i -a -n raghu mod_raghu.so

The -i option installs the module; -a option will automatically make changes in the Apache configuration file for this module by adding a line for loading this module; and -n option is just for explicitly setting a module name (for -i option).

The LoadModule Directive

The dynamic modules are loaded using the directive LoadModules in the configuration file of Apache (i.e. /etc/httpd/conf/httpd.conf). The syntax for LoadModules directive is:

LoadModule module_name file_for_module

A number of modules are already added for you. This is a part of httpd.conf file that shows the modules that are loaded by default:

# Dynamic Shared Object (DSO) Support
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so

These modules are added by default. Now suppose you want to add the module for increasing perl script execution speed, i.e. mod_perl. This can be done by adding this line in the configuration file httpd.conf:

LoadModule perl_module modules/mod_perl.so

After you have made some changes to httpd.conf, you need to restart the httpd service to make sure that the configuration file is read by the httpd deamon.

$ service httpd restart

Filed Under : WEB SERVERS

Tagged With :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.