Notice: Undefined index: order_next_posts in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 194

Notice: Undefined index: post_link_target in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 195

Notice: Undefined index: posts_featured_size in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 196

Develop Apache HTTP Server Modules

Apache HTTP Server is one of the most iconic open source projects in human history. It's also the world’s most used and respected web server. In this tutorial you'll learn how to add your own features to it…

This article originally appeared in issue 92 of Linux User & Developer magazine.

Subscribe and save more than 30% and receive our exclusive money back guarantee – click here to find out more.

As of February 2010, Apache served over 54.46% of all websites and over 66% of the million busiest. It is available on a wide variety of platforms including Linux, Mac OS X, Windows and BSD. One of the key factors behind Apache HTTP Server’s success is its modular architecture. The Apache HTTP Server core is very simple and doesn’t do much. The default distribution of HTTP Server contains the core and a set of core Apache Modules that handle most of the web-server-related operations. This modular architecture presents several benefits. For example, instead of running the full server, one can enable only the modules that one will use; this way one can run the most efficient version of the HTTP Server without changing the server code. Another benefit of modular architecture is extensibility. Apache as a web server community implements a defined feature set approved by the community, but that may or may not be enough for everybody. With extensible architecture, anybody can extend Apache HTTP Server according to their needs by developing Apache modules.

As mentioned previously, Apache HTTP Server comes with several built-in modules. You can run the following command to find out the list of built-in (or compiled-in) modules:
[bash]$ apachectl -l
Names starting from mod_ are the actual modules that we are talking about and can be disabled or enabled using the httpd.conf file.

The vanilla distribution (when compiled with default options) of Apache HTTP Server (2.2.16) comes with the following important modules…

mod_authn_file.c: This provides a user authentication system using plain text files.
mod_authn_default.c: This module provides fallback for the authentication system. If you have not configured an authentication module, this module will reject any credential provided by user.
mod_authz_host.c: Provides group authentication based on host name or IP address
mod_authz_groupfile.c: Provides group authentication using plain text files.
mod_authz_user.c: Provides the base user authentication system.
mod_include.c: Processes the server-side include files.
mod_filter.c: This module enables smart, context-sensitive configuration of output content filters.
mod_log_config.c: Provides logging system for client request.
mod_env.c: Modifies the environment which is passed to CGI scripts and SSI pages.
mod_mime.c: Provides the valid MIME type of a file that is being served.
mod_autoindex.c: Generates directory indexes automatically, similar to the UNIX
‘ls’ command.
mod_cgi.c: Provides support for CGI scripts.
mod_dir.c: Provides for ‘trailing slash’ redirects and serving directory index files.
mod_alias.c: Provides mapping support for file system directory and URL redirection.
mod_so.c: Provides support for module loading during server startup or restart.

Developing a ‘Hello World’ Apache Module
First of all perform the following steps to install Apache from source:
[bash]$ wget
$ tar xvfz http-*
$ cd httpd*
$ ./configure –prefix=$HOME/ludapache //This will install apache into ludapache folder in your home directory.
$ make
$ make install
By now you will have the Apache Web Server installed and configured to listen on default HTTP port, ie 80. On most of the UNIX systems, port 80 is reserved for the system web server and can only be run with root privileges. To run the web server in non-root mode we will need to make some changes to the Apache configuration file:
[bash]$ <HTTPD Direcotry>/conf/httpd.conf
In the following section, change ‘Listen 80’ to ‘Listen 3322’.
[bash]# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
Listen 3322

Continue to page 2 – building a ‘Hello World’ module

[twitter username=”linuxusermag”]