Installing Perl on Windows XP and using it with IIS.
This tutorial is about installing Perl 5 on Windows XP (32-bit) and using it with IIS, i.e. running Perl scripts on an IIS web server. It is supposed that you have IIS 5.1 installed . If not, or just in order to have a look at the actual website configuration on my Windows XP virtual machine, you might want to read my tutorial Installing Internet Information Server (IIS) on Windows XP. I installed Perl after having installed PHP. During that setup, I installed IIS Manager 6.0, that possibly (?) is required to successfully run Perl scripts. Please, have a look at my Installing PHP on Windows XP and using it with IIS tutorial and (if you want to be sure to succeed with Perl) consider to install IIS Manager 6.0 before installing Perl.
After the configuration of IIS as described in the two other tutorials, I had a working web server, with the website on wk-winxpe being accessible by entering http://wk-winxpe in the web browser's address field. On your system, you would probably use localhost or 127.0.0.1 instead of wk-winxpe.
Whereas nowadays, it's Strawberry Perl that's mostly used on Windows computers, at the time of Windows XP, the free Perl software from ActiveState was generally considered as "the Perl for Windows". This tutorial uses ActivePerl 5.22.1 that I downloaded from netzwelt.de. No idea if this is the most recent version of Perl that supports Windows XP. If you find the 5.22 version too old, you can try to find some newer release; if you want to be sure that your installation succeeds, you should use the one used in the tutorial.
The Perl download file is a Windows installer (MSI). The screenshot below shows the Welcome page of the setup program.
I used ActivePerl with Windows 2000 and XP long years ago, but I don't think that I ever realized how many features this software includes. In fact, there are several ways to use Perl with IIS, as for example Perl Scripting and PerlEx (no idea what this is). In this tutorial we will use Perl ISAPI. It's probably the most easy to configure and to use; and if you set up PHP for IIS, it will be quite the same for Perl.
The important point here is that Perl ISAPI is not installed by default. Thus, you'll have to explicitly mark it for installation in the components selection window.
Note: ActivePerl is free software, but using Perl ISAPI (as well as PerlEx, that you may or not also select for installation) in a production environment requires a license. So, if you should consider using Perl on Windows XP "in the real world"...
The setup program offers lots of options. They are all selected by default, and I let it like that. The important one is to add Perl to the PATH. I think that the creation of the virtual IIS directory for PerlEx wasn't done, and I think that the script mappings will not be needed (?) in our Perl ISAPI environment. Anyway, just use default settings...
To be sure that the new PATH environment variable is available, you should reboot your computer.
Lets start with trying Perl in Command Prompt. Here is the code of a simple "Hello user" program (I called it hello1.pl):
use strict; use warnings;
(my $name) = @ARGV;
$name = 'World' unless (defined $name);
print "\nHello $name!\n\n";
As the directory containing the Perl executable has been added to PATH, we can run Perl from any directory. Thus, the easiest way to run a script is to cd to the directory where it is located. We can quickly check if all works fine, displaying the Perl version by running the command perl -v. To run the sample program, run the command perl hello1.pl with or without command line argument.
To configure IIS for Perl, in IIS Manager 6.0, right-click your web server, and from the opening context menu choose Properties. In the Properties window, open the Home Directory tab. The lower part of this tab contains the IIS Application settings. Push the Configuration... button to set up Perl.
On the Mappings tab of the opening Application Configuration window, push the Add button to add the mapping for Perl ISAPI (screenshot on the left). In the Add/Edit Application Extension Mapping window, add the extension .plx and use the Browse button to add the C:\Perl\bin\perlis.dll DLL (you have to add the DLL, not perl.exe!) (screenshot on the right). Enabling all verbs is ok on a local test server. In the "real world", you would have to be more restrictive...
When pushing the OK button in the Application Configuration window, another window shows up, asking you if the child node "Printers" should use the new value of the "ScriptsMaps" property. I got similar configuration questions when setting up IIS. No idea, what this is about. I choose to use the new value for "Printers" (?).
In order to make the new configuration become active, you'll have to restart IIS.
Note: In the IIS configuration for Perl, I used the extension .plx, as this was mentioned as Perl ISAPI extension during the ActivePerl installation. I think that there is no problem to use the extension .pl instead.
To test Perl with IIS lets write a simple script to display the actual environment variables. Here is the code:
use strict; use warnings;
$|=1;
foreach my $var (sort keys %ENV) {
print $var . "=" . $ENV{$var} . "<br>\n";
}
Notes:
- Our Perl scripts use ISAPI, not CGI, so do not use the routines of the CGI module.
- Do not include instructions like print '<html>'; or print '<body>'; (if you do, the script execution will fail).
- Do not include the instruction print 'Content-type:text/html'; (this would be displayed as such on the webpage).
- Scripts using ISAPI Perl send everything that we print to the web browser. So, we can do "all normal printing", HTML tags being rendered as they should by the browser (for example, the "<br/>" in the code above, will be rendered as a linefeed).
- If you wonder what $|=1; is about, it's a directive that forces a flush after every print, so that the output appears as soon as it's generated rather than being buffered.
I named my script env.plx and placed it the webserver root directory (D:\inetpub\wwwroot on my Windows XP virtual machine). To access it, I entered http://wk-win10p/env.plx in the web browser address field (you would probably use localhost/env.plx). The screenshot below shows the Perl source file opened in the EditPad Lite text editor, and the output of the script in the Maxthon web browser.
If you like this page, please, support me and this website by signing my guestbook.