HTTPD mod_perl & mod_cgi

1. install mod_perl , mod_cgi

#yum -y install mod_perl mod_cgi

2. edit /etc/httpd/conf/httpd.conf

#vi /etc/httpd/conf/httpd.conf

LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module modules/mod_perl.so

3. edit /etc/httpd/conf/vhost.conf to handle cgi/perl
#vi /etc/httpd/conf/vhost.conf

<Directory “/path/to/your/perl-script-dir”>
AllowOverride all
DirectoryIndex index.php index.html
Options +ExecCGI
AddHandler cgi-script cgi pl

Order allow,deny
Allow from all
</Directory>

4. reload your httpd server

#service httpd reload

5. test to execute perl script by httpd

#cd /path/to/your/perl-script/dir
#vi test.pl

#!/usr/bin/perl
print “Content-type: text/plain\r\n\r\n”;
print “mod_perl rules!\n”;

6. chmod +x to tes.pl and test to run perl on the shell

#chmod +x test.pl
#perl ./test.pl

Content-type: text/plain

mod_perl rules!

7. go to your browser
http://hostname/path/to/your/perl-script-dir/test.pl

Content-type: text/plain

mod_perl rules!

Tags: , , , , , ,

This entry was posted on Saturday, August 8th, 2009 at 6:17 am and is filed under sysadmin. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply