Recipe 8.3 Using Windows File Extensionsto Launch CGI Programs
Problem
You want to have CGI
programs on Windows executed by the program associated with the file
extension. For example, you want .pl files to be
executed by perl.exe without having to change
the #! line to point at the right location.
Solution
Add the following line to your httpd.conf file:
ScriptInterpreterSource registry
Discussion
Since Apache has its roots in the Unixish world, there are a number
of things that are done the Unixish way, even on Microsoft Windows.
CGI execution is one of these things, but the
ScriptInterpreterSource directive allows you to have Apache
behave more in the way that Windows users are accustomed to.
Usually, on Windows, a file type is indicated by the file extension.
For example, a file named example.pl is
associated with the Perl executable; when a user clicks on this file
in the file explorer, Perl is invoked to execute this script. This
association is created when you install a particular program, such as
Perl or MS Word, and the association is stored in the Windows
registry.
On Unixish systems, on the other hand, most scripts contain the
location of their interpreter in the first line of the file, which
starts with the characters #!. This line is often
called the shebang line (short for sharp bang,
which are the shorthand names for the two characters).
For example, a Perl program might start with the line:
#!/usr/bin/perl
The shell running the script looks in this first line and uses the
program at the indicated path to interpret and execute the script. In
this way, files with arbitrary file extensions (or no extension at
all) may be invoked with any interpreter desired. In the case of
Perl, for example, one might have several versions of Perl installed,
and the particular version desired may be invoked by using the
appropriate #! line.
However, you may be accustomed to the operating
system's innate way of executing a program, and this
can be somewhat nonintuitive. Thus, in the early days of Apache on
Windows, the ScriptInterpreterSource directive was
added to make Apache behave the way that Windows users expected.
ScriptInterpreterSource may have one of two
values. When set to the default value, script,
Apache will look in the script itself for the location of the
interpreter that it is to use. When it is set to
registry, it will look in the Windows registry for
the mapping that is associated with the file's
extension and use this to execute the script.
This feature can be very useful for users who are running multiple
servers, some on Unixish operating systems and others on Windows, but
who want the same CGI programs to run both places. Because Perl is
unlikely to be located at /usr/bin/perl on your
Windows machine, using the
ScriptInterpreterSource directive allows you to run the
script unedited on Windows, simply by virtue of it having a
.pl file extension.
See Also
|