IIS 7 and Above
Perl as FastCGI
Last post Jun 30, 2011 06:37 AM by naderelshehabi
Jun 19, 2011 08:40 AM|NaderElshehabi|LINK
All over the internet are guides on how to run PHP via FastCGI, but almost no one is talking about Perl. Even those mentioning Perl are talking about ActivePerl. in Strawberry perl things are different.
I've managed to get Perl to run as CGI in IIS 7.5, but I wanted to either run it as ISAPI or as FastCGI. The Handler mapping of the CGI was "C:\perl\perl\bin\perl.exe %s". When I tried to replicate it in FastCGI I get "The
FastCGI executable could not be found" error!! PHP is working fine on my machine as FastCGI.
People say inActivePerl to use the PerlEx30.dll, which I couldn't find in Strawberry Perl. Any idea?
Jun 19, 2011 04:48 PM|HCamper|LINK
Have you checked this
in IIS Net Forum. The post contains information that may help.
For the Handler mapping you have posted is not correct it should be "C:\Perl\bin\perl.exe" "%s%" %s .
You currently have "C:\Perl\perl\bin\perl.exe %s" and that will not work.
Check the post and links for more information.
windows server 2008
Jun 19, 2011 09:41 PM|NaderElshehabi|LINK
Thank you for your reply,
Unfortunately the post talks about running Perl as CGI. What I'm trying is to run it as FastCGi. I already got it running as CGI. And strangely the "C:\Perl\perl\bin\perl.exe %s" does work by the way!
Do you know any sense in the %s syntax? What are the options?
Jun 20, 2011 01:41 AM|HCamper|LINK
You can use all the guides in the previous post for Perl PHP Ruby and other Script Engines.
Just so you know you can have *.pl as FastCGI and *.cgi as Perl.exe and *.pls as Perlex30.dll your choice.
Check the Combination of this
http://learn.iis.net/page.aspx/697/configure-php-process-recycling-behavior/ guides for PHP it works for Perl also.
The syntax fo "%s%" %s is a macro to allow for two arguments to be passed to Perl.
The logic for Perl "%s%" %s comes from how C++ works with Main Entry Point.
Yes your current Handler and Mapping may appear to work but your loosing functionallity.
Question how did you do the install to get "C:\Perl\perl\bin\perl.exe" instead of the standard "C:\Perl\bin\perl.exe".
You may find it useful to create Enviroment Variable PERLHOME that has the perl.exe path.
Jun 20, 2011 07:35 AM|NaderElshehabi|LINK
Thanks for your help. I still don't get the "%s%" %s syntax! Why the quotes and what are the available syntax? I mean is there a reference for this? Also PHP points only to php-cgi.exe without any arguments Also most people say it's
"%s" %s" not "%s%" %s, i.e. no second % after the first s.
Also all the posted guides talk about running perl as ISAPI while I'm trying to run it as
FastCGI. There is a difference. Using two Hello world pages; one in PHP as FastCGI and another in Perl as CGI rendered a response time of about 200 msec for the FastCGI and 800 msec for CGI. Why can't we run all scripting languages as FastCGI like
their site states? I know IIS FastCGI is MS implementation, but it should be the same?
The secret of my pain and the non standard "C:\Perl\perl\bin\perl.exe" path is that I'm using Strawberry Perl, not ActivePerl. That's why there is no PerlEx30.dll like all the guides say!
One note I'll be trying later is that I'm running Windows x64, FastCGI x64, and Perl is x86! Could that be it? All I want is how to debug this error?
Thanks for all your help.
Jun 20, 2011 09:13 AM|HCamper|LINK
You have a number of things that will be different for Which Perl you install and
how you configure and methods possible.
What to install or not install based on type of use and expectations:
You will save time and confusion by getting the Active State Perl Windows Installer for Windows intel X86.
The Active State Perl Community Edition installer is Freeware and has the ISAPI dll's built for Windows.
You do not need the Perl X64 version while running Windows amd X64 the Perl being X86 is not a problem.
To begin with Strawberry Perl is not built with the ISAPI extensions and will only
have CGI operations and the Handler is *.pl and PATH to Perl.exe with Verbs Get,Host,Post and
Restrictions for File and use as Script for Actions so that is the IIS Server simple settings.
The Strawberry Perl is a replacement for the Perl.org Distribution with somw bug fixes and extra libraries.
Why the parameters are and what use is this and common conventions:
The reason for the quotes is problems with Windows and PATH's and order of parsing parameters for Perl.
The Perl uses two macros %s% and %s to receive the first and second parameters which is C++ convention
which Perl expects for normal operation.
If you have only the first parameter Perl will appear to work but is missing functionallity.
If you check the Active State Documentation the Perl uses <% and code inside %> for operations
and matches the conventions for Asp which uses <% and code inside %> for Request and Response
and server side code.
The Active State Perl also adds Registery Entries for passing of parameters.
The macros allows you to escape the <% characters %> in the correct order and pass the values.
How to use FastCGI or ISAPI or CGI and have Handler and Mappings:
You can have Handler and a mapping for each type *.pl *.cgi *.pls and use CGI Perl Script or Perlex30.dll or FastCGI
the requirement is have a unique Name and Use a Module with that Mapping.
Yes you may find differences for Timing using FastCGI or ISAPI vs Script Engine Native.
The advantage of using FastCGI is it provides additional Control operations for Code and Script Execution.
There are differences for how ISAPI for Active Perl and FastCGI were built and functions.
You can use the FastCGI for all the scripting engines provided you use unique Name and Path to Script Engine.
The FastCGI by Microsoft and other ISAPI modules have differences for implementation and the Compilers use.
Suggestions and Options:
I suggest you check the link and guide at Web Panel web site and install the Active State Perl
and start with a Handler and mapping *.cgi and "C:\Perl\bin\perl.exe" "%s%" %s and Name CGI Perl.
Then using the guides create a FastCGI
Handler and Mapping for *.pl and FastCGI and "C:\Perl\bin\perl.exe" %s% %s and Name FastCGI Perl.
The FastCGI Handler Mapping you can use modified versions of the PHP variables to identify them for Perl.
The FastCGI Handler Mapping also allows you to set the max number of instances and recycling.
Final note: If you get gateway errors or execution errors while running scripts for Perl or PHP
you need to send Headers as first item that gets sent to IIS Server.
The expected format for the Header is "Content: type/text\n"; or Content: type/html\n"; as given by the http 1.1 RFC
conventions and standards.
The configuration for Perl can be dauting since the Web Does contain old guides and mixtures of Systems being used.
Hope I this helps,
Jun 20, 2011 10:49 AM|NaderElshehabi|LINK
Your reply was very informative. I couldn't get it to work though -changing the %s to "%s%" %s didn't have any effect-, yet at least I got more light on the matter. Perl and Python both working fine on IIS7.5 as CGI, yet as FastCGI I get the following error
in the failed request log:
The reason I chose Strawberry Perl is that it's free. Production license for ActivePerl is $1000 per server -At the time of this writing of course, and this info may be inaccurate. Any reader should refer to their site for accurate price-.
I marked your reply as an answer already. If you have any more thoughts about this mystery, I'd be extremely grateful. Otherwise, thanks a lot for your effort.
Jun 20, 2011 11:00 AM|HCamper|LINK
Yes, The Active State Perl Commercial Version is one thing.
You also have the Community Edition which is free
If you get the FastCGI Exit problems check that the Visual Studio runtimes are installed
and the FastCGI recycle settings are correct.
Check this guide
http://learn.iis.net/page.aspx/697/configure-php-process-recycling-behavior/ and item 4
you set the Environment and Requests values.
This is where you can define PERLHOME and set to C:\Perl\bin.
Jun 20, 2011 11:54 AM|NaderElshehabi|LINK
Environment variable set! Recycling settings are correct.. No change! Same error.
Jun 20, 2011 12:12 PM|HCamper|LINK
Check this post http://forums.iis.net/t/1178484.aspx for FastCGI Active Perl and Bugzilla
look at the ISAPI and CGI restrictions Picture and matching pane in IIS Manager it is possible to have duplicates.
The duplicates can cause errors and prevent you modifying the Path and Perl settings.
Jun 20, 2011 07:10 PM|HCamper|LINK
Question for Active State Perl and versions:
I checked the Perl comparisions Commercial vs Community Editions
and use for Perl and IIS Server what did you find that requires your getting the Commercial Distribution?
The Active State Perl Community Editions are used on many Windows IIS Servers ranging from IIS 5.1 to IIS 7.5.
Jun 20, 2011 11:11 PM|NaderElshehabi|LINK
These are the ISAPI and CGI restrictions, and since I'm trying to run Perl as FastCGI, it's the FastCGI settings module that should count. However; my ISAPI and CGI restrictions doesn't have duplicates.
I've contacted Active State concerning using their Perl. All over the internet it's said it's free. Actually they provide the community edition for developers and internal (non internet-facing) servers. Since my web server will be internet facing; their
sales said it should have the commercial version, regardless I needed the commercial support or not, and like I told you their commercial license is a bit overpriced in my opinion.
I know ActiveState should work like a snap since it's like you said have ISAPI extensions, but why not any perl? I believe they all work fine on Linux/Apache?
I even tried to run Perl on Apache/Windows.. Same issue!! But since I'm not an Apache guru I thought I did something wrong somewhere and tried to focus on IIS.
Jun 21, 2011 02:55 AM|HCamper|LINK
The the ISAPI and CGI restrictions will have Perl and a path for FastCGI use.
Ok it is good that the restrictions doesn't have duplicates.
Yes ActiveState should work like a snap.
Yes Perl works fine on Linux with Apache along with Perl for Apache for Windows.
Since you have had problems with Perl for Apache for Windows and IIS Server the problem could be with security.
As you state "I even tried to run Perl on Apache/Windows Same issue!! " which is security permissions and restrictions.
You do not need to be an Apache guru or IIS guru to make Perl work.
I suggest that we focus on IIS server security and permissions for trouble shooting.
for Users and Accounts required permissions.
for Turning on and Enable "Failed Requests Tracing".
A guide for the Status code for IIS Server
http://support.microsoft.com/kb/943891 which has the Status codes
Typically if you add the IUSR and IIS_USRS Accounts to the IIS Server
along with the C:\Perl installation with read,execute,list permissions it resolves majority of problems.
Jun 21, 2011 07:31 AM|NaderElshehabi|LINK
Well, I covered the credentials part alright! I even desperately tried to give full conteol to Everyone group!!
Jun 22, 2011 04:46 AM|HCamper|LINK
Ok You have the permissions set for IIS Server Perl Folder and Web Sites.
How about using a Simple Handler and mapping for Perl that uses FastCGI as part of the Method.
If you use IIS Manager and go to the Machine Icon and Add Mapping using FastCGI Module
for *.pl with Verbs Get,Header,Post with Request as File and Limits to use
Script and supply the Path as "C:\Perl\bin\perl.exe" "%s%" %s
and then enable the Mapping.
Then goto the FastCGI section and set the Recycling and variables as needed.
Then check that the Handler and Mapping are in the Default Web Site and Enable the Mapping.
Check that the FastCGI Settings are present. Restart the IIS Server to make sure it is updated.
Then check which Application Pool is being used for Default Web SIte Both the Version and Type Classic or Integrated.
Then test the mapping by using the env.pl script supplied by Active State from the C:\inetpub\wwwroot\env.pl using the
browser using http:// localhost / env.pl and check the results.
You may find changing the Application Pool settings will have an effect of script execution.
Jun 22, 2011 06:57 AM|NaderElshehabi|LINK
I go with your post step by step.
Jun 23, 2011 04:00 PM|HCamper|LINK
Ok, You might try different using the path "C:\Perl\bin\perl" "%s%" and see if that works?
Additional item the images in the post do not display.
If you have SkyDrive account and Public Folders you can then can link the images so they can be displayed.
Jun 25, 2011 08:04 AM|NaderElshehabi|LINK
The images were screen shots illustrating the steps I wrote. Unfortunately I copy / pasted them into the rich editor so there are lost. Anyway, I tried the path you provided earlier and it doesn't work either.
I'm convinced that Perl doesn't work as FastCGI on Windows for some reason, perhaps related to the concept of Forking / Threads. I just wonder why does PHP work fine?
This is a call to the Microsoft FastCGI team to test and implement Perl as FastCGI on Windows/IIS and prepare a clear guide on how to configure it.
Jun 26, 2011 07:04 AM|HCamper|LINK
Ok, The pictures got lost so may you can remove the dead links then.
I think if you recheck Wades Post again
and look at the step #2 the instructions are for setting the Application Pool and the Advanced Settings
and select "Enable 32-Bit Applications" and set it to "True".
I found that if the Application Pool settings are incorrect you will get the 500 errors and failures.
I spent time checking the Application Pools using VM for Vista Ultimate and was able to get the failures.
Hope this helps,
Jun 26, 2011 09:29 AM|NaderElshehabi|LINK
Man, I really appreciate your persistence. However, my application pool is already 32-bit enabled.
You mentioned that you got the failures on your VM. Does that mean you actually got it to work on your VM? Did you get Perl to run as FastCGI on IIS?
Jun 28, 2011 02:24 AM|HCamper|LINK
Ok, Then you have the Application Pool set for 32-bit then.
Yes the FastCGI works on Vista and Perl same as the configuration for FastCGI and PHP.
I do not have Windows 2008 Server to test the settings.
The Vista VM does work as a test of the settings.
It is not so much persistence as it is trying to understand why FastCGI is not working for your system.
May be if you check IIS Net PHP FastCGI guides use them for the Perl Settings.
Edit: Problems with Windows 2008 Vista Update Microsoft Support
The update is for PHP and Script Engines.
Jun 30, 2011 06:37 AM|NaderElshehabi|LINK
Excellent! I'm surprised it's that easy on Vista. I actually have tested configuration on both Windows 7 and server 2008. Not t mention the tons of posts of people having similar issue so I thought it's not possible.
Would you be kind enough to share the exact settings -screen shots, step by step guide, etc..- to how you did it? I'm even willing to download your entire VM just to understand this issue.
I'll try to set up a Vista my self and go through this post step by step. Maybe I can get to something. Thanks for everything.