I have set up a local Perl web environment on my Windows machine. The application I'm working on is originally from a Linux server, and so the shebang for source .pl
files look like so:
#!/usr/bin/perl
This causes the following error on my Windows dev machine:
(OS 2)The system cannot find the file specified.
Is it possible to change my Apache 2 conf so that the shebang is ignored on my Windows machine? Of course I could set the shebang to #!c:\perl\bin\perl.exe
, that much is obvious; but the problem comes to deploying the updated files. Clearly it would be very inconvenient to change this back on each deploy. I am using ActivePerl on Windows 7.
I should have mentioned that I need to keep the shebang so that the scripts will work on our shared hosting Linux production server. If I did not have this constraint and I didn't have to use the shebang, the obvious answer would be to just not use it.
I use #!/usr/bin/perl
in my scripts and configure Apache on Windows to ignore the shebang line. Add
ScriptInterpreterSource Registry-Strict
to your httpd.conf
and set up the Windows Registry key as explained in the Apache docs.
Here is what I get when I export the key:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.pl\Shell\ExecCGI\Command] @="c:\\opt\\perl\\bin\\perl.exe"
I have been using this setup with Apache and ActiveState Perl on my Windows laptop and the Apache and Perl distributions that come with ArchLinux on my server.
The Apache docs (to which I linked above) state:
The option Registry-Strict which is new in Apache 2.0 does the same thing as Registry but uses only the subkey
Shell\ExecCGI\Command
. TheExecCGI
key is not a common one. It must be configured manually in the windows registry and hence prevents accidental program calls on your system. (emphasis mine)
Create a trivial redirecting shell script:
exec "@"
Create a registry entry:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.cgi\Shell\ExecCGI\Command]
@="<path-to-sh> <path-to-script>"
[HKEY_CLASSES_ROOT\.pl\Shell\ExecCGI\Command]
@="<path-to-sh> <path-to-script>"
[HKEY_CLASSES_ROOT\.py\Shell\ExecCGI\Command]
@="<path-to-sh> <path-to-script>"
(...and so on.)
Jot in your httpd.conf
file:
ScriptInterpreterSource Registry
Apache will now resolve Unix shebangs relative to the interpretation given by your choosen Bash flavor. This gives much more flexibility than hardcoding interpreter paths in the registry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With