If you, like me and many others, use ActiveState Perl to execute Perl CGI scripts on Windows web servers, you might run in to a problem with recent versions of Apache httpd and ActiveState Perl. The latter comes with an installer that makes use with IIS relatively seamless, but using it with httpd requires a tiny bit of tinkering.
With default installs of both (and havng enabled the .cgi Script Handler and using the ExecCGI option in httpd configs), you might find that .cgi files with the (reasonably) standard
#!/usr/bin/perl
shebang/hashbang line won’t work out of the box (as they have for many previous versions of httpd/Perl). The error message in the httpd logs, for me, look like:
[Mon Jan 14 11:01:32 2008] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't create child process: 720002: envtest.cgi [Mon Jan 14 11:01:32 2008] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't spawn child process: D:/abc/xyz/web sites/intranet/envtest.cgi
The quick fix is to add the -w
flag to your shebang line, but that involves changing (potentially) many files, and can produce output in the logs that isn’t necessarily severe warnings. Again, you can control the warning levels in the scripts but that, too, involves changing files.
The second workaround is to use the
ScriptInterpreterSource
config (which, in fairness, is documented in the distributed httpd.conf). This tells httpd to use the Windows registry to find out how to execute a given file/script (e.g. .cgi or .pl) and ignore the shebang line. So while this workaround might involve a little more work initially, it does save the need to modify all your CGI/Perl scripts. Here, in brief, is how this workaround is done:
- Enable the ScriptInterpreterSource option in your httpd.conf, as documented in the default/distributed example:
ScriptInterpreterSource registry
- Add a registry key to map the .cgi extension to Perl (.pl is already done by the Perl installer). Use
regedit.exe
to add a Key named “.cgi” toHKEY_LOCAL_MACHINE\SOFTWARE\Classes
. In that new key, change the default String (REG_SZ
) value to “Perl” (which matches another key that the installer has added). That’s all! - Make sure you have
ExecCGI
option enabled in your conf files or .htaccess, as normal - Restart Apache
That works for me!
Leave a Reply