Install mod_perl to optimize the execution of Perl scripts in Apache httpd.
mod_perlInstall mod_perl from the EPEL repository.
# Enable EPEL and install mod_perl
[root@www ~]# dnf --enablerepo=epel -y install mod_perl
Configure PerlRun mode to always keep the Perl interpreter in RAM.
# Edit the Perl configuration
[root@www ~]# vi /etc/httpd/conf.d/perl.conf
# Modify the configuration as follows
# Uncomment and check codes, output warnings to logs
PerlSwitches -w
# Uncomment
PerlSwitches -T
# Uncomment and configure the Perl directory
Alias /perl /var/www/perl
<Directory /var/www/perl>
SetHandler perl-script
AddHandler perl-script .cgi
PerlResponseHandler ModPerl::PerlRun
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>
# Uncomment and configure the status page
<Location /perl-status>
SetHandler perl-script
PerlResponseHandler Apache2::Status
Require ip 127.0.0.1 10.0.0.0/24
</Location>
# Restart httpd to apply changes
[root@www ~]# systemctl restart httpd
Create a test script to verify the PerlRun mode settings.
# Create a directory and test script
[root@www ~]# mkdir /var/www/perl
[root@www ~]# vi /var/www/perl/test-mod_perl.cgi
# Add the following Perl script
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/html\n\n";
my $a = 0;
&number();
sub number {
$a++;
print "number \$a = $a \n";
}
# Set appropriate permissions
[root@www ~]# chmod 705 /var/www/perl/test-mod_perl.cgi
# Test the script
[root@www ~]# curl https://www.emc.world/perl/test-mod_perl.cgi
number $a = 1
Registry mode caches executed code in RAM for faster execution.
# Edit the Perl configuration for Registry mode
[root@www ~]# vi /etc/httpd/conf.d/perl.conf
# Modify the configuration for Registry mode
Alias /perl /var/www/perl
<Directory /var/www/perl>
AddHandler perl-script .cgi
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>
# Reload httpd to apply changes
[root@www ~]# systemctl reload httpd
Access the test script to see variable caching in action.
# Access the test script multiple times
[root@www ~]# curl https://www.emc.world/perl/test-mod_perl.cgi
number $a = 1
[root@www ~]# curl https://www.emc.world/perl/test-mod_perl.cgi
number $a = 2
# Modify the script for Registry mode
[root@www ~]# vi /var/www/perl/test-mod_perl.cgi
# Update the Perl script
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/html\n\n";
my $a = 0;
&number($a);
sub number {
my($a) = @_;
$a++;
print "number \$a = $a \n";
}
# Test the script again
[root@www ~]# curl https://www.emc.world/perl/test-mod_perl.cgi
number $a = 1
Access the mod_perl status page.
# Access the mod_perl status page
Open your web browser and navigate to http://[your-hostname-or-IP]/perl-status
This configuration allows for the efficient execution of Perl scripts in Apache httpd, leveraging mod_perl for improved performance.