Perl + mod_perl
Perl + mod_perl 
2015/07/30 
 | 
Install mod_perl to make Perl scripts be fast. 
 | |
| [1] | Install mod_perl. | 
# install from EPEL 
[root@www ~]# 
yum --enablerepo=epel -y install mod_perl 
 | 
| [2] | Configure PerlRun mode which always put Perl interpreter on RAM. | 
[root@www ~]#  
vi /etc/httpd/conf.d/perl.conf 
# line 15: uncomment ( check codes and output warnings to logs ) 
PerlSwitches -w 
# line 24: uncomment 
PerlSwitches -T 
# line 30-36: uncomment like follows 
Alias /perl /var/www/perl <Directory /var/www/perl> 
# the directory for mod_perl environment 
SetHandler perl-script 
# processes files as perl-scripts under this directory 
#    AddHandler perl-script .cgi  
# set specific extension if do do not want to processes all files as CGI 
# PerlResponseHandler ModPerl::Registry 
PerlResponseHandler ModPerl::PerlRun 
# specify PerlRun mode 
PerlOptions +ParseHeaders Options +ExecCGI </Directory> 
# line 43-49: uncomment and add like follows 
<Location /perl-status> SetHandler perl-script PerlResponseHandler Apache2::Status 
Require ip 127.0.0.1 10.0.0.0/24  
# add access permission 
# Order deny,allow # Deny from all # Allow from .example.com </Location> 
systemctl restart httpd  
 | 
| [3] | Create a test Script to make sure the settings are no ploblem. It's OK if the result like follows is displayed. | 
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width:100%; font-size:40px; font-weight:bold; text-align:center;\">";
my $a = 0;
&number();
print "</div>\n</body>\n</html>";
sub number {
    $a++;
    print "number \$a = $a";
}
chmod 705 /var/www/perl/test-mod_perl.cgi  
 | 
| [4] | Configure Registry mode which has caches of codes on RAM. | 
[root@www ~]#  
vi /etc/httpd/conf.d/perl.conf 
Alias /perl /var/www/perl 
[root@www ~]# <Directory /var/www/perl> SetHandler perl-script PerlResponseHandler ModPerl::Registry 
# uncomment 
# 
   PerlResponseHandler ModPerl::PerlRun
# comment out 
PerlOptions +ParseHeaders Options +ExecCGI </Directory> 
systemctl restart httpd  
 | 
| [5] | Access to the test script which is an example of [4] section, then variable increases by reloading because variable is cached on RAM. So it's necessarry to edit the code for Registry mode. | 
[root@www ~]#  
vi /var/www/perl/test-mod_perl.cgi 
#!/usr/bin/perl use strict; use warnings; print "Content-type: text/html\n\n"; print "<html>\n<body>\n"; print "<div style=\"width:100%; font-size:40px; font-weight:bold; text-align:center;\">"; my $a = 0; 
&number( 
$a 
);print "</div>\n</body>\n</html>";
sub number {
    my($a) = @_;  
    $a++;
    print "number \$a = $a";
}
 | 
| [6] | By the way, it's possible to see the status of mod_perl to access to "http://(hostname or IP address)/perl-status". | 
Comentários
Postar um comentário