Running Perl on IIS 7

We've had a few people on our forums asking about running Perl on IIS 7. This led to some discussion on the team about getting it to work with FastCGI.

The team has been doing a lot of great work with the Web Platform Installer and Windows Web App Gallery that feature popular PHP applications. Since PHP runs best on IIS with FastCGI, I suppose it was logical to turn to FastCGI for Perl as well.

Sometimes, though, the right tool for the job is not the newest and flashiest thing. It turns out that this is the case for Perl. For many years, ActiveState has provided a free version of ActivePerl that runs great on IIS using ISAPI instead of FastCGI.

It's been a while since I've looked at ActivePerl, so I did some research last week to see the state of things and discovered that there are a few things you need to know in order to get it to work on IIS 7:

ActivePerl is available as an ISAPI for 32 bits only. This does not prevent it from running on a 64 bit install of Windows. It just means that any application pool that contains Perl content must be configured to run as 32 bit.

As of this writing, ActivePerl runs well on IIS 7, but its installer does not properly configure IIS 7 for running Perl scripts. After completing the ActivePerl installation, you will need to create handler mappings to associate requests for Perl scripts to the correct ISAPI based Perl interpreter.

There are at least two different ISAPI extensions with ActivePerl. You should make sure that you use PerlEx30.dll with IIS 7. If you use perlis.dll, you may find that response headers sent from your Perl script are added to your response page instead of going back to the client as headers.

Given the above information, here are the steps to get ActivePerl running on IIS 7:

1. Install ActivePerl from http://www.activestate.com/activeperl/. At this time, there is a link to version 5.10 for Windows (x86) on this page. This link downloads an MSI installer to your machine which you can run.

2. If you are running the 64 bit version of Windows 2008, ensure that your application pool is configured to run as 32 bit. Assuming that you will be using ActivePerl in the default application pool, these steps will do it:

  • From the Windows 'Start' menu, pick run and type "inetmgr" (without the quotes). Click on 'OK".
  • In the left hand pane of IIS Manager, open up the settings for your server. Click on "Application Pools".
  • In the Application Pools page, select "DefaultAppPool".
  • In the right hand pane, under "Edit Application Pool", click on "Advance Settings..."
  • In the Advanced Settings dialog, ensure that "Enable 32-bit Applications" is set to "True".

3. Create a handler mapping that associates "*.pl" requests with ActiveState's perlex30.dll extension using the following steps:

4. In the left hand pane of IIS Manager, select your server. This will apply the following handler mappings on the entire server. If you would like to do this for just a specific site or application, you can open up the server and select any site or application. In the center pane, double click on the Handler Mappings icon.

5. When the Handler Mappings pane is displayed, click on the "Add Module Mapping..." item in the Actions pane on the right.

6. Fill out the Add Module Mapping dialog as follows:

  • For Request Path, enter "*.pl".
  • For Module, select "IsapiModule" from the dropdown list. Note that the ISAPI module is a prerequisite. If it does not show up on this list, it will need to be installed an an IIS optional component.
  • For Executable, enter "c:\perl\bin\PerlEx30.dll" (without the quotes.) Note that this assumes that you've installed ActiveState Perl using its default location. If you installed it in another location, you will need to look there for perlex30.dll.
  • For Name, enter "ActiveState Perl for .pl". Note that this name is just a label and does not affect functionality. It does need to be unique, though. If you are going to be associating other file extensions with ActiveState Perl, the names for those mappings will need to be different.
  • You do not need to do anything with the "Request Restrictions..." button. If you wish to limit this mapping to specific HTTP verbs, etc., it can be done there.

7. Repeat the above steps for any additional file extensions you wish to be associated with Perl. On IIS 6, ActiveState Perl creates mappings for "*.pl", "*.plx" and "*.plex". Additionally, some applications are known to map "*.cgi" with Perl.

That's it. After doing this, ActiveState Perl should run on IIS 7.

18 Comments

  • okay what am I missing here?

    I have these instructions as well:

    Executable: C:\Perl\bin\perl.exe "%s" %s
    Extension:.cgi
    Verbs Limit to: GET,HEAD,POST
    Check that file exists: (uncheck this box)

    What is this and where does it go?

  • I'm wondering what version of ActivePerl I should install.

    They have a 64 bits version (ActivePerl-5.10.1.1006-MSWin32-x64-291086.msi) that gets installed in C:\perl64\

    Should I install that version and if so, do I still need to configure my application pool to run as 32 bit?

    Thanks a lot!

  • Answering my own question from November: I should read the article! :)

    "ActivePerl is available as an ISAPI for 32 bits only. This does not prevent it from running on a 64 bit install of Windows. It just means that any application pool that contains Perl content must be configured to run as 32 bit."

    Let's repeat, you need to install the 32 bits version of ActivePerl.

  • I finally got perl to run partially but it isn't behaving right. I mapped to PerlEx30.dll as instructed above. I really don't know how to describe what it's doing.

  • Thanks a million. This worked great! Very good and clear instructions.

  • This was a great article, thanks. However, I'm still having an odd problem and was wondering if someone can shed light on it.

    Here's the issue: all my scripts work fine on a single-machine XP instance with a local database. However, my production servers are two 2008 Server boxes set up with the 32-bit ODBC connector to a SQL Express DB. With the default IIS7 config, a given script in production works fine the first time. If you try to use the same script again within a given period (seems like about 10-15 minutes) all the form parameters passed by the HTML simply vanish and are not seen in the new request.

    Once that rough timeout period expires, the script will work again. Once.

    I've tried turning off caching (no effect); restarting IIS (again allows a script to work once; and setting the Recycling options for the AppPool containing the Perl scripts to a very low interval, like 2 minutes. The latter works, but obviously is not optimal.

    Does anyone have a suggestion about this? I'd really like a workable fix.

  • My problem is very similar to the one described above. My scripts work perfect for about 5 or 10 minutes and then go all to hell. If I restart they work again for 5 or 10 minutes. Can anyone help?

  • I just went through the whole thing again with a fresh install of Windows 7 on a new computer, 32 bit this time. After following the directions to the letter again I came up with the exact same result. My new computer is behaving exactly the way my laptop does when running perl. So now I have a Laptop with Win7 64 bit and a desktop with Win7 32 bit. Both not running perl correctly and exhibiting the exact same behavior. Has no one else run across this? Is there no answer? Will our hero be dashed on the rocks below?
    Tune in next week...

  • I have been swithing around the .dll files to see if that makes a difference. It does. It looks like only 2 will work at all. PerlEx30.dll and Perlis.dll. I have been working with PerlEx30.dll as directed by the instructions. Now I tried Perlis.dll and it is better in some ways but still not correct. Perlis.dll appearantly has trouble with headers.

  • I have been swithing around the .dll files to see if that makes a difference. It does. It looks like only 2 will work at all. PerlEx30.dll and Perlis.dll. I have been working with PerlEx30.dll as directed by the instructions. Now I tried Perlis.dll and it is better in some ways but still not correct. Perlis.dll appearantly has trouble with headers.

  • I would really appreciate an update on this topic. The new version of Active Perl IS a 64-bit version and doesn't have the .dll specified above. I can't get my .cgi scripts to run on localhost (IIS 7) but they will run on a Unix server just fine.

  • @jmrathbun,

    ActivePerl x64 on IIS 7 (5.12.3.1204) - This is running fine for me on W2K8 x64. I ran the MSI installer, set all features except "Perl" to "unavailable" (don't need ActiveX, docs or examples), and unchecked all the setup option boxes as well. I prefer to set paths and mappings manually. Next, I added a script map (under Handler Mappings) to *.pl, %SystemDrive%\Perl64\bin\perl.exe "%s" %s

    I did not have to enable 32-bit applications. Also, script mapping is CgiModule, not IsapiModule (which is Module Mapping). Seems to execute my .pl files just fine! If your scripts are .cgi, then use *.cgi instead of *.pl when adding your script mapping. Make sure under Request Restrictions that you enable "script" access. You will probably want to set "Invoke handler only if request is mapped to: file" as well.



  • hi all ,
    I do the setting follow the post step by step

    the .pl script can run correct on localhost
    but if I use serverName replace "localhost", when I use IE to access the link.

    IE will pop a file download dialogure box. ask me download the perl file or not.

    btw, the IsapiModule can not add parameters.

  • Hello @ All,

    From a Recent Post in IIS Net Forum User felix found an updated Active State Perl installation guide:
    At the Web Panel Web Site.

    http://www.websitepanel.net/kb/installing-and-running-active-perl-runtime-as-isapi-on-microsoft-iis-7.0
    Martin
    Cheers:)

  • HI,

    i have recently set-up a new IIS server, we host an online parts request system written in perl. i have installed perl as described above. the scripts run ok however you mention in your installation instructions,

    "There are at least two different ISAPI extensions with ActivePerl. You should make sure that you use PerlEx30.dll with IIS 7. If you use perlis.dll, you may find that response headers sent from your Perl script are added to your response page instead of going back to the client as headers."

    I have used the PerlEx30.dll but i am still seeing this happen. When I send Post info to the script when logging a request the headers are returned as expected, but then they appear at the top of every subsequent page. but what is also happening is that these headers will then appear at the top of each page on every other client's pc. It seems that IIS is keeping the headers in some kind of memory and sending them with each subsequent HHTP request.

    Is there any way of stopping this. I have disabled all Session States, Caching etc but cannot get it to work.

    Thanks

    Michael

  • Hello,
    I your having problems with perl and IIS Server:
    http://www.iislogs.com/steveschofield/hosting-perl-on-iis-7.x-thread Perl collection information.
    Martin

Comments have been disabled for this content.