Configuring apache 2.2.4 + mod_perl 2.0 + php 5.2.3 + libapreq with a worker MPM

I couldn’t find any docs on compiling mod_perl2 alongside php5 with apache 2.2, so hopefully this helps someone.

I’ve always statically compiled mod_perl into apache, but the easiest way to get mod_perl to play nice with PHP under apache2 is to compile them as DSO’s or dynamic modules that are inserted at runtime. I’ve tested this under Ubuntu 7 and CentOS 5.

At the time of this writing the server hosting this page is running with this config and handles a not-insignificant amount of traffic.

NOTE: I use a worker MPM with Apache to get the best possible performance. The worker MPM is a hybrid thread/process model. It requires that PHP be threadsafe when compiled.

Here are the commands I use. I’m assuming you’ve downloaded the latest apache httpd 2.2 source code, php’s source code, mod_perl’s source code and libapreq2’s source code. I’m assuming you’re smart enough to know when to CD to the directory of each app to compile and install that app, so I’ve left out basic steps like that.

First compile apache with DSO support. Enable the worker MPM, enable mod_rewrite, enable mod_expires, and add a little magic to make libapreq work:

./configure –prefix=/usr/local/apache2 –with-mpm=worker –enable-so –enable-rewrite –enable-expires –with-included-apr

make

make install

Now that apache is installed, compile and install a thread-safe PHP DSO . Note the enable-maintainer-zts compiles a threadsafe PHP. I’ve also added mysql support.

./configure –with-mysql –enable-maintainer-zts –with-apxs2=/usr/local/apache2/bin/apxs

make

make install

Now you compile and install a mod_perl DSO.

perl Makefile.PL –with-apache2-apxs=/usr/local/apache2/bin/apxs

make

make install

Next you compile and install libapreq as a DSO

perl Makefile.PL –with-apache2-apxs=/usr/local/apache2/bin/apxs

make

make install

Make sure your httpd.conf contains the following to enable mod_perl, php and libapreq:

LoadModule apreq_module /usr/local/apache2/modules/mod_apreq2.so
LoadModule perl_module modules/mod_perl.so
LoadModule php5_module modules/libphp5.so
DirectoryIndex index.html index.htm index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Comments

4 responses to “Configuring apache 2.2.4 + mod_perl 2.0 + php 5.2.3 + libapreq with a worker MPM”

  1. Brian Avatar
    Brian

    Thank you! Just what I was looking for.

  2. Mark Beyer Avatar
    Mark Beyer

    Thanks ! It’s amazing that there isn’t an easily readable document like this on apache.org, perl.org and so on…

    Mark

  3. Ycart I Avatar
    Ycart I

    Can you help me with mod_perl 2.0? I can’t get it to locate that MP_APXS. I’ve been Googling for days just to get it installed, but still when I try makefile.pl, it won’t work, producing this error:

    usr@linuxbox:/mod_perl-2.0.7$ perl Makefile.PL –with-apache2-apxs=/usr/sbin/apxs
    Reading Makefile.PL args from @ARGV
    MP_APXS unspecified, using /usr/sbin/apxs

    no conflicting prior mod_perl version found – good.
    ************* WARNING *************

    Your Perl is configured to link against libgdbm,
    but libgdbm.so was not found.
    You could just symlink it to /usr/lib/i386-linux-gnu/libgdbm.so.3.0.0

    ************* WARNING *************
    Configuring Apache/2.2.22 mod_perl/2.0.7 Perl/v5.14.2
    [ error] ‘/usr/sbin/apxs -q APR_BINDIR’ failed:
    [ error] Use of assignment to $[ is deprecated at /usr/sbin/apxs line 135.
    apxs:Warning: /usr/sbin/httpd not found or not executable
    apxs:Warning: Continuing anyway…
    apxs:Warning: No shared object support for Apache
    apxs:Warning: available under your platform. Make sure
    apxs:Warning: the Apache module mod_so is compiled into
    apxs:Warning: your server binary `/usr/sbin/httpd’.
    apsx:Warning: Continuing anyway…
    apxs:Error: Invalid query string `APR_BINDIR’
    [ error] ‘/usr/sbin/apxs -q BINDIR’ failed:
    [ error] Use of assignment to $[ is deprecated at /usr/sbin/apxs line 135.
    apxs:Warning: /usr/sbin/httpd not found or not executable
    apxs:Warning: Continuing anyway…
    apxs:Warning: No shared object support for Apache
    apxs:Warning: available under your platform. Make sure
    apxs:Warning: the Apache module mod_so is compiled into
    apxs:Warning: your server binary `/usr/sbin/httpd’.
    apsx:Warning: Continuing anyway…
    apxs:Error: Invalid query string `BINDIR’
    [ error] Can’t find apr include/ directory,
    [ error] use MP_APR_CONFIG=/path/to/apr-config

  4. Margene Brunet Avatar
    Margene Brunet

    You will be the worst author

Leave a Reply

Your email address will not be published. Required fields are marked *