search
top

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.

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.

6 Responses to “Install mod_perl on Apache 2.2 on Windows 7”

  1. Clark says:

    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

  2. Alyssa Stella says:

    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.

  3. Alyssa Stella says:

    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

  4. Alyssa Stella says:

    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!

Leave a Reply

Your email address will not be published. Required fields are marked *

top