Configuring mod_perl for Red Hat 8.0 and Apache 2.0

by Dennis G. Allard<allard@oceanpark.com>,
- revised -


After I set up Red Hat 8.0, mod_perl did not work even after I
followed the advice in /usr/share/doc/httpd-2.0.40/migration.html,
which is a file that is part of the Red Hat 8.0 distribution.

begin Caveat.

I use the convention of placing my web documents and scripts beneath
/home/httpd/ as opposed to beneath /var.  I keep all data and
non-system applications beneath /home or /usr/local, since by backing
up /home and /usr/local, I know that I have backed up all non-OS
stuff.  Also, in theory, when I upgrade my OS, I can keep /home and
/usr/local unchanged.

So, below you will see /home/httpd in some places.  Your milage may vary.

End caveat


Following instructions in /usr/share/doc/httpd-2.0.40/migration.html,
I modified /etc/httpd/conf.d/perl.conf to contain the lines:

    LoadModule perl_module modules/mod_perl.so

    Alias /perl /home/httpd/perl
    <Directory /home/httpd/perl>
      SetHandler perl-script
      PerlHandler ModPerl::Registry::handler
      PerlOptions +ParseHeaders
      Options +ExecCGI
    </Directory>


That means that perl scripts beneath /home/httpd/perl will be handled
by the mod_perl Apache module.  I believe directory /etc/httpd/conf.d
is a Red Hat convention and you must have the following line in
/etc/httpd/conf/httpd.conf:


  Include conf.d/*.conf


With the above in place, I would then get errors such as:

    Error message: Can't locate Apache.pm in @INC (@INC contains:
    /home/httpd/perl/db /home/httpd/perl/lib
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at
    /usr/lib/perl5/5.8.0/CGI.pm line 161. Compilation failed in require at
    /home/httpd/perl/lib/Templates.pm line 56. BEGIN failed--compilation
    aborted at /home/httpd/perl/lib/Templates.pm line 56. Compilation
    failed in require at /home/httpd/perl/logon/logon.pl line 16. BEGIN
    failed--compilation aborted at /home/httpd/perl/logon/logon.pl line 16.

I got things working by following advice I found at:

    http://perl.apache.org/docs/2.0/user/porting/compat.html

which explains that by using Apache::compat, scripts that used to
work in mod_perl 1.0 will work in mod_perl 2.0.

To use Apache::compat, I created /home/httpd/perl/startup.pl containing:

    #!/usr/bin/perl
    use Apache::compat ();
    1;

I then added the following lines to /etc/httpd/conf/httpd.conf:

    AcceptPathInfo on
    PerlRequire /home/httpd/perl/startup.pl


At the point when I start using mod_perl for production purposes, I
will take the time to port my old mod_perl 1.0 code to true mod_perl 2.0,
which will enable removing the above usage of Apache::compat.

Note, for vanilla CGI perl scripts (those not handled by mod_perl),
things worked once I put the following into /etc/httpd/conf/httpd.conf:

    Options ExecCGI
    ScriptAlias /bin/ /home/httpd/bin/
    ScriptAlias /cgi-bin/ /home/httpd/bin/
    AddHandler cgi-script .pl

That permitted Perl scripts placed beneath /home/httpd/bin/ or
/home/httpd/cgi-bin/ to work fine.  But those are not handled by
mod_perl, since I configured mod_perl, an Apache module, to handle
scripts that are below /home/httpd/perl (see above).


Back to Ocean Park