
The default apache configuration installed without mod_perl. This can be a good idea in order to minimize the number of things that can go wrong. This post will covers the steps to enable mod_perl on linux CentOS 6.3. This will make Perl script be fast and increase the performance
1. To Enable mod_perl, simply run the following command :
[root@centos63 ~]# yum install mod_perl -y
Loaded plugins: fastestmirror, presto, priorities
Loading mirror speeds from cached hostfile
* base: centos.ipserverone.com
* extras: centos.ipserverone.com
* updates: centos.ipserverone.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mod_perl.i686 0:2.0.4-10.el6 will be installed
--> Processing Dependency: perl(BSD::Resource) for package: mod_perl-2.0.4-10.el6.i686
--> Running transaction check
---> Package perl-BSD-Resource.i686 0:1.29.03-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================
Package Arch Version Repository Size
====================================================================================================
Installing:
mod_perl i686 2.0.4-10.el6 base 3.2 M
Installing for dependencies:
perl-BSD-Resource i686 1.29.03-3.el6 base 35 k
Transaction Summary
====================================================================================================
Install 2 Package(s)
Total download size: 3.2 M
Installed size: 6.0 M
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 3.2 M
(1/2): mod_perl-2.0.4-10.el6.i686.rpm | 3.2 MB 00:27
(2/2): perl-BSD-Resource-1.29.03-3.el6.i686.rpm | 35 kB 00:00
----------------------------------------------------------------------------------------------------
Total 117 kB/s | 3.2 MB 00:27
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-BSD-Resource-1.29.03-3.el6.i686 1/2
Installing : mod_perl-2.0.4-10.el6.i686 2/2
Verifying : mod_perl-2.0.4-10.el6.i686 1/2
Verifying : perl-BSD-Resource-1.29.03-3.el6.i686 2/2
Installed:
mod_perl.i686 0:2.0.4-10.el6
Dependency Installed:
perl-BSD-Resource.i686 0:1.29.03-3.el6
Complete!
2. Configure PerlRun mode :
[root@centos63 ~]# vi /etc/httpd/conf.d/perl.conf
a) Original :
#PerlSwitches -w
Uncomment or change to :
PerlSwitches -w
b) Original :
#PerlSwitches -T
Uncomment or change to :
PerlSwitches -T
c) Original :
#Alias /perl /var/www/perl
#<Directory /var/www/perl>
# SetHandler perl-script
# PerlResponseHandler ModPerl::Registry
# PerlOptions +ParseHeaders
# Options +ExecCGI
#</Directory>
Uncomment or change to :
Alias /perl /var/www/perl
<Directory /var/www/perl>
SetHandler perl-script
# AddHandler perl-script .cgi
# PerlResponseHandler ModPerl::Registry
PerlResponseHandler ModPerl::PerlRun
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>
d) Original :
#<Location /perl-status>
# SetHandler perl-script
# PerlResponseHandler Apache2::Status
# Order deny,allow
# Deny from all
# Allow from .example.com
#</Location>
Uncomment or change to :
<Location /perl-status>
SetHandler perl-script
PerlResponseHandler Apache2::Status
Order deny,allow
Deny from all
Allow from 192.168.2.0/24
</Location>
3. Restart Apache :
[root@centos63 ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
4. Make sure if it works normally :
Browse to http://192.168.2.54/perl-status

5. Configure Registry mode :
Alias /perl /var/www/perl
<Directory /var/www/perl>
SetHandler perl-script
# AddHandler perl-script .cgi
PerlResponseHandler ModPerl::Registry
# PerlResponseHandler ModPerl::PerlRun
PerlOptions +ParseHeaders
Options +ExecCGI
</Directory>
6. Restart Apache :
[root@centos63 ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]