Install mod_perl on Apache 2.2 on Windows 7
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-5.10.1.5.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.
1 |
c:\> cd C:\strawberry |
Run the command
1 |
c:\strawberry> perl\bin\perl.exe update_env.pl.bat |
Next download and compile the mod_perl using ppm (Perl Package Manager)
1 |
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.
1 2 |
LoadModule perl_module modules/mod_perl.so LoadFile "C:/strawberry/perl/bin/perl510.dll" |
Find the mime section and modify this
1 |
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.
1 |
ScriptAlias /cgi-bin/ "c:/Apache2/cgi-bin/" |
Next you will need to add ExecCGI in the Option section.
1 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!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.
update_env.pl.bat doesn’t exist, and the ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd doesn’t work too..
how to fix this?
C:\strawberry\perl\bin>ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod
_perl.ppd
Installing package ‘http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd’…
Error installing package ‘http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd
‘: Could not locate a PPD file for package http://cpan.uwinnipeg.ca/PPMPackages/
10xx/mod_perl.ppd
Clark,
If you browse to http://cpan.uwinnipeg.ca/PPMPackages/10xx/ the files are listed but clicking on the hyperlink returns a 503 error from their web server. If you browse to the page there is mention of two other locations that you can try.
A set of repositories, suitable for adding to the ppm utility of ActivePerl 10xx, is given below – make sure to add only those repositories corresponding to your Perl version, as reported by C:\>perl -v.
http://www.bribes.org/perl/ppm, for the http://www.bribes.org Perl 5.10 repository
http://trouchelle.com/ppm10/, for the trouchelle Perl 5.10 repository
http://cpan.uwinnipeg.ca/PPMPackages/10xx/, for the uwinnipeg Perl 5.10 repository
Try ppm install http://www.bribes.org/perl/ppm/mod_perl.ppd or ppm install http://trouchelle.com/ppm10/mod_perl.ppd
I just HAVE to thank you newlife007, I spent my entire weekend trying to get this to run. I was extremely frustrated. I thought it would never work. Even the official documentations were completely unclear to me but this.. completely did the trick. You are my hero, have a great day.
Glad I could help out!
Hey it’s me again,
Last night I got an issue with my Windows 8 so I went back to W7. And re-did my entire Apache installation and used this article again as reference for my perl installation.
I get stuck on the “ppm install [link to ppm]” command.
Upon execution, it runs fine, package downloads but it doesn’t ask me where I want to install it to. Instead I get the message “Installing files in blib/lib into architecture dependent library tree”.
I for the life of me, have no idea where that is.
It should work like it did yesterday, it’s the exact same strawberry perl version. Any idea?
Thanks!
Aly
I should’ve tried a little harder. I found the solution.
It placed the file in the ppm folder in the strawberry directory, which I invoked from CMD. I was then prompted to download the perl module, it also asked me where I wanted to place it. Thanks again newlife and goodluck to others!