oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Build Your Own Apache Server with mod_perl

by David Wheeler

Editor's note: be sure to see David Wheeler's update to this article, Installing libapreq on Jaguar: An Update.

When Apple released Mac OS X, it included as part of the operating system one of the most powerful and most-used applications on the Internet today: the Apache Web server. This has been a boon for Mac users and dedicated Unix jocks alike, as the combination of Apache's simplicity and power and the legendary Mac OS ease-of-use has made for a robust Internet application development platform. Largely due to the inclusion of Apache, along with a host of other necessary Unix power tools, Mac OS X has rapidly become the Unix developer's platform of choice.

And lest anyone be concerned, the Apache that ships with Mac OS X is the genuine article. We're not talking about a weak, proof-of-concept port of Apache that runs under Windows. Mac OS X's FreeBSD underpinnings allow for the Apache Web server to be as flexible and responsive as it is on any Unix-based operating system. See Kevin Hemenway's Apache Web-Serving with Mac OS X series for a comprehensive overview of those features and how to take advantage of them under Mac OS X.

However, the version of Apache included with Mac OS X is arguably unsatisfactory in a number of ways. If you're like me and plan to do some serious mod_perl-based Web development work on Mac OS X, you'll need to take the following issues into consideration as you begin working with Apple's Apache install:

Related Reading

Apache: The Definitive Guide
By Ben Laurie, Peter Laurie

  • Although it includes support for mod_perl, it is as a dynamically loadable library (dynlib), which means that Perl can be dynamically loaded into the Apache binary at startup time. Unfortunately, a quick search of the mod_perl users mail list or the HTML::Mason users list archives reveals that the dynamically loadable mod_perl is notoriously unstable. As a result, most serious mod_perl users prefer to statically compile mod_perl right into the Apache binary.
  • The version of Perl supported by Apple's Apache is the same as that included with Mac OS X: 5.6.0. Although Apple has provided instructions on how to compile the newer, more robust Perl 5.8.0 yourself, doing so won't automatically make mod_perl use Perl 5.8.0. You have to compile mod_perl yourself to get the latest and greatest.
  • Although new versions of Apache are regularly released to fix bugs or patch security holes, Mac OS X users must wait for an OS update from Apple to enjoy the benefits of the latest releases. That time lag can leave OS X Apache users exposed to known security issues until Apple provides an update.
  • If you'd like to take advantage of the efficiencies that the mod_perl modules Apache::Request and Apache::Cookie offer over the commonly used CGI module, you're out of luck, since they have yet to be ported to Mac OS X.

For those whose Web serving needs have exceeded the capabilities of the Apple-supplied Apache, and for those who need to develop scalable Web applications built on Perl 5.8.0, mod_perl, and Apache::Requst & Apache::Cookie, an important alternative exists: you can build your own Apache Web server on Mac OS X. In this article, I guide you through the steps necessary to build your own Apache server with mod_perl.


Compiling your own applications means that you need a compiler. Apple kindly offers one with the Mac OS X Developer tools. You'll need to grab them from Apple's developer site (free registration) and install them.

If we're to install Apache with mod_perl, the first thing we need to do is install the latest version of Perl. Fortunately, Apple has provided the aforementioned instructions for downloading and compiling Perl 5.8.0. Although that article documents compiling Perl 5.8.0 on Jaguar, it should work reasonably well on Mac OS X 10.1.x, as well.

Next, we'll need to download and patch the latest Apache 1.3 and mod_perl 1.x sources. You can find the Apache sources on the Apache HTTP server Source Code Distributions page, or at your nearest mirror. As I write this, the latest version is 1.3.26, so that's what I'll use in the remainder of this article. The latest version of mod_perl is available from the mod_perl distribution page.

% cd /usr/local/src
% curl -O
% tar zxvf apache_1.3.26.tar.gz
% curl -O
% tar zxvf mod_perl-1.0-current.tar.gz

Following Apple's example, I move into the /usr/local/src directory and do all of the work there. I've used the handy curl utility to download the Apache and mod_perl sources right in my Terminal session. I then used the tar program to unpack the sources. The Apache sources will now be in the directory apache_1.3.26/, while the mod_perl sources will be in the directory mod_perl-1.xx/ As of this writing, the current version of mod_perl is 1.27, so I'll be working in the mod_perl-1.27/ directory in the examples below.

As I mentioned before, the mod_perl Apache::Request and Apache::Cookie modules--part of the apreq library--have not yet been ported to Mac OS X. However, as a workaround, the apreq developers have put together a patch to compile the C interface to apreq right into Apache. This approach circumvents the issues with the regular apreq library, allowing Apache::Request and Apache::Cookie to work perfectly well on Mac OS X.

% curl -O
% curl -O
% cd apache_1.3.26
% patch -p0 < ../apreq.patch

Once again, I use curl to download the files I need, in this case the apreq sources and the apreq patch to Apache. I then move into the apache source code directory and use the patch program to patch the Apache sources. What this means is that patch takes the contents of the apreq.patch file and uses them to change the existing Apache source files to directly support apreq.


Now we're ready to start building the software. At this point, you should have downloaded, compiled, and installed Perl as per the instructions from Apple (with the source code still living in /usr/local/src/perl-5.8.0), and followed the steps outlined above. Next we'll build mod_perl.

Like most source code installations, mod_perl offers a good number of configuration options. A quick perusal of the installation guide reveals all. However, I'm going to recommend a relatively straightforward configuration that includes support for all of the mod_perl features you're likely to need, while allowing the flexibility to build other Apache modules into Apache later on. Here it is:

% cd ../mod_perl-1.27
% perl Makefile.PL \
  APACHE_SRC=../apache_1.3.26/src \
  NO_HTTPD=1 \

The perl script Makefile.PL creates the Makefile that will be used to compile mod_perl. The APACHE_SRC option tells Makefile.PL where to find the Apache sources. The NO_HTTPD option, meanwhile, forces the build process to use this path but keeps it from compiling Apache before we're ready. The USE_APACI option is what allows that flexibility as it enables mod_perl's "hybrid build environment," wherein we can later compile other modules into Apache. Meanwhile, the PREP_HTTPD option triggers the build process to set up the Apache sources for mod_perl by preparing the APACHE_SRC/modules/perl/ directory tree. But we save the most important option for last. The EVERYTHING option enables all of mod_perl's features.

When this command runs, you'll be prompted to confirm to configure mod_perl with the APACHE_SRC sources. Do so by simply hitting the return key. At this point, mod_perl's configuration will quickly take care of all of its tasks without further intervention.

Next we'll build and install mod_perl. Fortunately, the tricky part is over. All we need to do is this:

% make
% sudo make install

These two steps build mod_perl and install it. But before we can take advantage of the newly installed mod_perl, we need to configure and build Apache.

% cd ../apache_1.3.26
% ./configure \
    --with-layout=Apache \
    --enable-module=so \
    --activate-module=src/modules/perl/libperl.a \
    --disable-shared=perl \

Once again the configuration is the most complex part of the process. The --with-layout=Apache option sets up Apache to be installed with its usual file system layout (i.e., in the /usr/local/apache directory). The --enable-module=so option enables dynamically loadable library support, should you decide later to build and use any third party modules as dynamically loadable objects. The --activate-module=src/modules/perl/libperl.a option activates mod_perl, while --disable-shared=perl option forces Apache to compile in mod_perl statically, rather than as a dynamically loadable library. And finally, the --without-execstrip option is required on Mac OS X to prevent the Apache binary from being stripped (whatever that means).

After configure does its job, we compile and install Apache with the usual commands:

% make
% sudo make install

The final step in this process is to compile the apreq libarary. Although the apreq patch added statically compiled support for apreq directly into the Apache binary, we still need to build and install the Perl modules that will allow us to take advantage of it. Fortunately, this last step is easy, as it follows the usual approach for installing Perl modules:

% tar zxvf apreq.tar.gz
% cd httpd-apreq
% perl Makefile.PL
% make
% sudo make install

Pages: 1, 2

Next Pagearrow