Koozali.org: home of the SME Server

mod_perl

scd

mod_perl
« on: May 23, 2007, 01:14:44 AM »
I had difficulties getting mod_perl to work on SME 7.0 and subsequently 7.1.

Installing mod_perl using yum went OK, but using mod_perl caused errors. For example the suggested yum install
> yum --enablerepo=base --enablerepo=updates --enablerepo=addons install mod_perl
installed seemlessly but errors occur when using mod_perl handlers in apache. There is a further problem when installing Mason as well which I think is related. I think the basic problem may be the perl CGI version used in SME7 is to old for Apache2.

I have written a quick howto to so others may avoid the pain. I am not an expert at this sort of stuff so I may have made a mistake.

After installing mod_perl.i386 using yum, using mod_perl handlers in apache caused errors when trying to reference Apache::Registry. Below is the error message I was getting in the error log:
[Fri Jul 14 17:21:16 2006] [error] [client 192.168.1.11] failed to resolve handler `Apache::Registry\': Can\'t locate loadable object for module Apache::Constants in @INC (@INC contains: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl . /etc/httpd/ /etc/httpd/lib/perl) at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/mod_perl.pm line 14\\nCompilation failed in require at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache.pm line 6.\\nBEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache.pm line 6.\\nCompilation failed in require at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache/Registry.pm line 2.\\nBEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache/Registry.pm line 2.\\nCompilation failed in require at (eval 2) line 3.\\n


The problem was fixed in a later RedHat rpm
  * mod_perl-2.0.1-1.rhel4.i386.rpm

with the following rpm dependancies:
  * perl-CGI.pm-3.11-1.mp2.noarch.rpm
  * perl-FCGI-0.67-1.2.el4.rf.i386.rpm
  * perl-BSD-Resource-1.28-1.el4.rf.i386.rpm

After installing the rpms do a
> config setprop modPerl status enabled

To test the mod_perl is working you will have to update the httpd.conf file. Actually in SME7 you do not update httpd.conf but rather add templates to /etc/e-smith/templates-custom.

http://perl.apache.org/ has some good easy examples to follow. Make sure you use the examples for apache 2 and mod_perl 2. Two things you want to test is
 1. Can you run a cgi-perl script using Apache::Registry. For this you can write a perl cgi script as you would normally. Apache::Registry caches the compiled script so that subsequent invocations run 50 times faster.
 2. Can you call a perl handler directly. This a piece of perl code which is loaded into the httpd process. Rather then terminating after the request has been served the process stays active waiting to server another request without having to reload and compile your perl code. Again this is a much faster way to respond to requests.

Below are the modified files that can be configured with SME7 to demonstrate mod_perl.

--------- CONFIGURE HTTPD.CONF  ----------
file '/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/99TestConfig'
################ Test Configuration ####
#### Configuration set up here may be removed once the system is operational
#### Testing mod_perl handler
PerlRequire /home/e-smith/files/ibays/Primary/test/require.pl
<Location /mod_perl-handler>
    SetHandler perl-script
    PerlResponseHandler TestModPerl::Message
</Location>
####  Testing mod_perl ModPerl::Registry
Alias /mod_perl-cgi/ /home/e-smith/files/ibays/Primary/test/cgi-bin/
<Location /mod_perl-cgi/>
    SetHandler perl-script
    PerlResponseHandler ModPerl::Registry
    PerlOptions +ParseHeaders
    Options +ExecCGI
    Order allow,deny
    Allow from all
</Location>

--------- CONFIGURE PERL LIBRARY PATH  ----------
file '/home/e-smith/files/ibays/Primary/test/require.pl'
use lib qw(/home/e-smith/files/ibays/Primary/test/perllib);
1;

--------- NORMAL CGI-BIN PERL SCRIPT  ----------
file '/home/e-smith/files/ibays/Primary/test/cgi-bin/hello.cgi'
#!/usr/bin/perl -w
print "Content-type: text/plain\n\n";
print "mod_perl 2.0 rocks!\n";

--------- NORMAL CGI-BIN PERL SCRIPT  ----------
file '/home/e-smith/files/ibays/Primary/test/perllib/TestModPerl/Message.pm'
package TestModPerl::Message;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
my $counter = 0;
sub handler {
    my $r = shift;
    $counter++;
    $r->content_type('text/plain');
    print "mod_perl 2.0 rocks!\n";
    print "Requests server by httpd process: $counter\n";
    return Apache2::Const::OK;
}
1;

The two examples may be demonstrated through using a url similar to
http://www.example.com/mod_perl-cgi/hello.cgi
http://www.example.com/mod_perl-handler

Simon Dale