Apache 2.4 on RHEL 7 - replacing mod_perl.so and VirtualHost variables for CGI::Compile

2k views Asked by At

I'm currently porting and old Perl-based application into AWS. I successfully made Perl run alongside Apache 2.4 and even got my PostgreSQL database up and running.

Then I proceeded configure Apache's httpd.conf to properly load all the resources necessary for the system to work. I got most of them up and running after some research. However, I simply can't get around LoadModule perl_module modules/mod_perl.so

From what I've researched so far, mod_perl.so has been deprecated in Apache 2.4 on RHEL 7, and as indicated on RHEL 7's website this module should be replaced by something else - they suggest mod_fcgid, but after discussing the issue internally, we decided to go with PSGI's CGI::Emulate::PSGI and CGI::Compile as our replacement, basically because it would allow us to not mess up hundreds of old scripts to change print orders.

However, I can´t get them to work. Trying to call them withing a script causes Perl to not find CGI::Compile, and attempting to install this module through CPAN results in an error MIYAGAWA/CGI-Compile-0.22.tar.gz : writemakefile NO '/usr/bin/perl Build.PL ' returned status 512

Below is an example of the code I´m using (file myPSGIScript.psgi):

#!/usr/bin/perl

use strict;

use CGI::Compile;
use CGI::Emulate::PSGI;

my $sub = CGI::Compile->compile("/var/www/cgi-bin/testScript.pl");
my $app = CGI::Emulate::PSGI->handler($sub);

Where testScript.pl is a simulation of one of our scripts, including calls to CGI and other modules that we need, placed on the same folder:

#!/usr/bin/perl

use strict;
use CGI qw/:standard :html/;
$CGI::HEADERS_ONCE++;
$|=1;

print header;

use Pg;

my $test = param('test');

print <<BlocoWeb;
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>AWS Test</title>
        </head>
        <body>
                <center>
                        <h1>
                                I'm working - $test -
                        </h1>
                        <br>
                        <form action='./testScript.pl'>
                                <input type='text' name='test' value='$test'>
                                <input type='submit'>
                        </form>
                </center>
        </body>
</html>
BlocoWeb

Am I misunderstanding how these libraries are supposed to work? Do I need to import them on Apache's httpd.conf or something? Or is it something else? Should I give up on this idea and use mod_fcgid instead - and how?

Also, mod_perl is what enables us to set certain parameters inside <VirtualHost> tag that are crucial for our application to work, namely PerlOptions +GlobalRequest, PerlModule and PerlSetVar. Is there a way using this method that would allow these to be set?

For reference, I'm on RHEL 7, Apache 2.4.6, Perl 5.16.3 inside Amazon's AWS.


EDIT: This is not the answer I was looking for, but it actually solved my issues, so I believe it's worth adding to this post just in case.

After a lot of research, I figured out from Amazon's knowledge base that you can actually get your hands on mod_perl.so on RHEL 6 and 7 and other distributions they proide. All you have to do is enable their Extra Packages through the proper command. In my case:

sudo yum install –y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

After running the appropriate command, run sudo yum repolist and check if the following repositories are available:

 epel/x86_64                                           Extra Packages for Enterprise Linux 7 - x86_64
 rhui-REGION-rhel-server-optional/7Server/x86_64       Red Hat Enterprise Linux Server 7 Optional (RPMs)

If they are, you're ready to go and run sudo yum install -y mod_perl and it should be available for loading on Apache's conf file.

Again, this solved my issues for the moment but Red Hat's message is clear: don't use this unless you absolutely need to. If you can, upgrading your code to another newer module is the best thing to do.

0

There are 0 answers