Saturday, June 25, 2011

Perl - How to install and configure Perl with Apache web server on windows

1. Install ActivePerl on your windows machine as per your OS.

2. Downlaod "mod_perl.so" file and place under "Apache/modules" folder.

3. Create "startup.pl" under "apache at your system/conf/extra".

use ModPerl::Util ();
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();
use Apache2::ServerRec ();
use Apache2::ServerUtil ();
use Apache2::Connection ();
use Apache2::Log ();
use Apache2::Const -compile => ':common';
use APR::Const -compile => ':common';
use APR::Table ();
use Apache2::compat ();
use ModPerl::Registry ();
use CGI ();
1;

4. Create "httpd-perl.conf" under "apache at your system/conf/extra".

LoadFile "Perl/at/your/system/path/bin/perl-x.dll"
LoadModule perl_module modules/mod_perl.so
PerlPostConfigRequire "apache at your system/conf/extra/startup.pl"

AddType text/html .pl

SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders

SetHandler cgi-script

5. Restart your apache and write the below test perl code under your web-root as "demo.pl"

print "Content-type: text/plain;\n\n";
print "Hello Perl"

6. Run the code in web browser as

http://web-root/demo.pl