Apache with Static Mod_Perl and Mod_DSO



One of the really cool things about the Apache web server is its flexibility: there are a number of modules that you can include to extend the usefulness of Apache. Some, such as mod_auth, mod_auth_ldap, mod_auth_external and mod_auth_mysql allow the Apache web server to authenticate users before allowing access to web documents. Other modules, such as mod_perl and mod_php build programming language interpreters into Apache--making CGI programs very fast.

In my own humble (or whatever :) opinion, two of the most useful modules for Apache are mod_DSO and mod_perl. mod_dso allows the server administrator to add modules to Apache without needing to completely rebuild the server. Say you've got an Apache server running, but now you need to add the ability to server secure (encrypted) web pages. You could download mod_ssl and rebuild the web server, but as long as you've compiled mod_dso into the server at the beginning, you don't have to. Instead, you can use apxs to link mod_ssl to the already existing server installation--VERY cool!

So why not build Apache with mod_dso, and add mod_perl as a dynamic module, you might ask. Unfortunately, those with more programming experience than I recommend that you not build mod_perl as a DSO module, because as a DSO, it can, in some installations, develop a memory leak. This problem does not seem to occur when mod_perl has been built as a static module, however.

Getting Started:
First, you need to get the Apache and mod_perl sources:

The typical *nix download and unpack sequence:
  • Download the file into your source directory (I will assume /usr/local/src, in this document)
  • Unpack the source into your build environment:
    • cd /usr/local/src
    • tar -xvzf /usr/local/src/apache_1.3.31.tgz (or whatever version you have downloaded)
    • cd ..
    • tar -xvzf /usr/local/src/mod_perl-1.0-current.tar.gz (again, "or whatever")
    Note:
Building the Software:
cd to the mod_perl directory
  • cd /usr/local/mod_perl_1.29 (or whatever version you have--I'll omit these comments for the rest of the "howto")
...and build Apache with mod_perl and mod_dso support:
  • perl Makefile.PL \
      APACHE_PREFIX=/usr/local/apache_1.3.31 \
      APACHE_SRC=/usr/local/src/apache_1.3.31/src \
      DO_HTTPD=1 \
      USE_APACI=1 \
      EVERYTHING=1 \
      APACI_ARGS='--enable-shared=max, --enable-module=most'
  • make
  • make test
  • make install
Congratulations: You should now have a complete Apache web server with mod_perl and mod_dso statically built into the module. You will still need to edit your Apache configuration file, but that's beyond the scope of this "howto". Once that is done, however, your Perl CGI scripts should be much faster than they were without mod_perl, and if you need to add other modules besides the ones included with Apache, you should be able to use apxs to include them without recompiling your source.

this server kicks @5$ becuase it is powered by Apache/Linux! image copyright Michael Wallette, 2004.  If you like it, feel free to use it, but don't sell it!