To continue on with developing on Windows using Apache/MySQL/PHP I wanted to add mod_perl to the mix. For this post I chose to make it work on Apache 2.2 but it could possibly work on Apache 2.4 as well, but I have not tested they portion yet.
First piece of the puzzle is to download a version of Perl that supports the Module on Apache. In the past I have gone with ActiveState’s ActivePerl but lately I have been using Strawberry Perl due to changes in retrieving older releases.I settled on Perl 5.10 release.
Download Strawberry Perl 5.10.5 from http://strawberryperl.com/releases.html and click on strawberry-perl-126.96.36.199.msi under the Strawberry Perl May 2011 section.
Once downloaded just double-click to install it, you can change the default installation path or change it to your preference. Once the installation is completed then, open a command prompt to set the perl environment and reboot the system.
c:\> cd C:\strawberry
Run the command
c:\strawberry> perl\bin\perl.exe update_env.pl.bat
Next download and compile the mod_perl using ppm (Perl Package Manager)
ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd
The installation process will start. Once it compiles the module it will ask where to put it. This will be your Apache modules directory (ex:c:/Apache2/modules)
Close the command prompt and edit c:\Apache2\conf\httpd.conf
We must tell Apache to load the module and tell it where the perl Dll lives. You can add this to the bottom of the file.
LoadModule perl_module modules/mod_perl.so LoadFile "C:/strawberry/perl/bin/perl510.dll"
Find the mime section and modify this
AddHandler cgi-script .cgi .plx .plex .pl
Now we need to enable and add a few items to allow perl to execute.
Look for the alias_module section and make sure the cgi-bin line is pointed to the correct location.
ScriptAlias /cgi-bin/ "c:/Apache2/cgi-bin/"
Next you will need to add ExecCGI in the Option section.
Options Indexes FollowSymLinks ExecCGI
Save the changes and restart Apache service. We are now ready to test to see if it displays a simple Perl Hello script.
You can copy the code and save it as test.pl in c:\apache2\htdocs or anther directory of your preference.
#!c:\strawberry\perl\bin\perl.exe # ^^^ this must be the first line of the script! ^^^ # start code use strict; use CGI; my $q = new CGI; # print header and start the markup output print $q->header( "text/html" ),$q->start_html( "hello from perl cgi!" ); print $q->h2("Hello Mark..."); print $q->end_html; # end code
I hope this helps get Perl working in your Windows Apache install.