Overriding the perl shebang line for Apache on Windows

Apache can execute perl (or other cgi like) scripts even on Windows, but when you transfer files tested on a Unix environment to a Windows based installation you will have to modify every first line of each script as this contains the pointer to perl on the system, the so-called shebang line. I recently installed Bugzilla and encountered the following errors in the browser screen:

Server error!<br />
The server encountered an internal error and was unable to complete your request.<br />
Error message: couldn't create child process:<br />
720003: relogin.cgi<br />
If you think this is a server error, please contact the webmaster.<br />
Error 500

and in the Apache log files:

[Tue Mar 06 12:54:42 2007] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : couldn't create child process: 720003: relogin.cgi, referer: http://localhost/bugs/
[Tue Mar 06 12:54:42 2007] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : couldn't spawn child process: C:/Program Files/bugzilla-2.22.1/relogin.cgi, referer: http://localhost/bugs/

However there is a workaround, which will make live a lot easier for you.

If you program your scripts to use the default shebang line for unix and linux like systems:

#! /usr/bin/perl -wT

you can use them without modification on Windows based systems if you make sure you have the following registry key implemented on your Windows server, but make sure the last line points to the actual location of the perl executable.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.cgi]
[HKEY_CLASSES_ROOT\.cgi\Shell]
[HKEY_CLASSES_ROOT\.cgi\Shell\ExecCGI]
[HKEY_CLASSES_ROOT\.cgi\Shell\ExecCGI\Command]
@="C:\\Perl\\bin\\perl.exe -T"

Add the above contents to a plain text file and save it using a filename with the extension .reg. After saving double click on it and confirm that you want it added to the registry. After that your Apache should be able to execute perl scripts without complaining, or you could download the registry file here.

My own server

Since a few years I have been interested in SME Server and since a few months I have my own domain and my own server using SME Server. You can find me at http://www.snetram.nl.
SME Server is based on CentOS and is a highly flexible but easy to manage Linux flavoured server. Among many things it holds a webserver and a database server.