a contribution to the oddities of the observable universe...

Perl on WAMPSERVER

Friday, September 05, 2008

This is a how-to guide on enabling perl in your Window's WAMP 2.0 setup.

Just in case you are wondering, I've tested this under Windows XP Home Edition with SP 3

In this how-to, I'm assuming that you have already installed WAMP 2.0, it is already running in your Windows setup, and you simply have the base/initial configuration of WAMPServer 2.0.

In this how-to, let's assume that WAMP is installed in X:\wamp\

Download and install ActivePerl from http://perl.activestate.org, I'm using version 5.10 and haven't tried out other versions. ActiveState has been doing a great a job at providing Perl for Windows, their installers pretty much takes care of everything you need. No need to mess with your Windows environment variables. Anyway, where you will actually be installing ActivePerl is up to you. Just take note or remember which directory it's installed.

If you are a fan of convention and in keeping with WAMP's directory convention, I would assume that you have ActivePerl installed in X:\wamp\bin\perl. Confirm that you have perl installed by opening a command prompt and type perl -v

That should display which version of perl you have installed in your system. Now, that we are sure we have perl installed we can move on to setting up our Apache to handle perl scripts.

To do that, open your httpd.conf file. In our example, it should be in X:\wamp\bin\apache\apache2.2.6\conf\

<Directory "cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

Now change this to

<Directory "X:/wamp/bin/apache/apache2.2.6/cgi-bin/">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

The above directory directive configures Apache to run CGI scripts under the X:/wamp/bin/apache/apache2.2.6/cgi-bin/ directory. The configuration above assumes that you will be putting your perl scripts in a single location. Of course, you can configure your cgi-bin directory to be placed elsewhere. Configuring your Apache's VirtualHost to have it's own dedicated cgi-bin directory is another how-to topic that I'll be writing about.

After that, search for the code below, it is a commented Apache configuration line.

#AddHandler cgi-script .cgi

and change it to, or uncomment the line and add .pl before .cgi

AddHandler cgi-script .pl .cgi

That will essentially tell Apache to interpret .pl and .cgi files as CGI scripts. The perl scripts I write are for Linux. Hence, my scripts begin with #!/usr/bin/perl. Since we are in Windows, we have to replace the shebang line with the correct path to our ActivePerl installation #!X:/wamp/bin/perl/bin/perl.exe

At this point, we are finished configuring WAMP's Apache. Now what? let's test if we have our Apache running our perl scripts properly. Fire up your favorite editor and open X:/wamp/bin/apache/apache2.2.6/cgi-bin/printenv.pl and replace the line #!/usr/bin/perl with #!X:/wamp/bin/perl/bin/perl.exe. Save and open up a browser and point it to http://localhost/cgi-bin/printenv.pl

If you see the Window's environment variables available for perl then you're set! Happy testing on your WAMP with Perl enabled.

While prepackaged systems are great in that they mostly have the items we need during development, I do not recommend that you use any of them for production sites.

Even the team who developed the prepacked system I've written a how-to for has this recommendation in their CHM help file:

WAMP5 is not designed for production but as a development environment. With WAMP5, you will be able to create you scripts locally on your computer, test them and then upload them on your production server.

There is nothing preventing you from using these prepackaged system so to ensure that a secure system, get them from their official sites. This will ensure that you have reliable copy.

If you hold a VPS or a Dedicated Server, it would be best that you get the sources for the server and languages that you need and compile them from source. This ensures that your production site does not have the unnecessary bloat. Better yet, if you have been itching for a more stable and cost-effective system, switch to Linux.

If you've learned a thing or two from this post, please don't forget to drop me a line. I'll also be writing articles about configuring Linux for web development, watch out for them. Til next time!

6 comments:

James said...

thank you, that was very helpful!

Garima said...

Hi,
Read your solution for Perl on Wamp.
It is great help ,i followed all your instruction and intall Wamp with Perl on my machine.
Actully i want to install bugzilla using Wamp server which requires

1.MySql
2.Apache
3.perl
and i am facing some problem with perl modules.
Can You please help me out.

Gabriel said...

I just want to say thank very much for this silver bullet. Before today, I didn't even know what WAMP was, and now not only do I have a virtual server, but I've stapled Perl onto it. Again: THANK YOU.

audienceone said...

@Garima, I took some time to install bugzilla, visited their site and followed the installation instructions. It worked for me.

I did not do an online install rather I download the perl modules that is needed to install and bugzilla. Bugzilla is working well on my win.

Nihat Pearl said...

Thank you so much. It was very helpful. I added perl to my wamp server easily with your instructions

Anonymous said...

i have install perl on wamp but when i open up a browser and point it to http://localhost/cgi-bin/printenv.pl

1. i couldn't see the Window's environment variables available for perl
2. how i can install database module for perl

please help me

Thanks
Yogesh