http://www.perlmonks.org?node_id=34770

clemburg has asked for the wisdom of the Perl Monks concerning the following question:

Under NT, how does apache find the perl interpreter when executing Perl CGI scripts?

How can one influence this?

Originally posted as a Categorized Question.

  • Comment on How does apache under NT find the perl interpreter?

Replies are listed 'Best First'.
Re: How does apache under NT find the perl interpreter?
by japhy (Canon) on Sep 30, 2000 at 23:54 UTC
    Believe it or not, Apache looks at your #! line. YES, it's true! The #! line IS USED in Windows!
      Umm, not exactly.

      Apache 1.3.4 and earlier did use the shebang, but 1.3.6 and higher do the usual Win32 thing of executing by file extension.

      Perl itself does check the shebang for switches, but that's perl rather than apache. Ugly

Re: How does apache under NT find the perl interpreter?
by Wysardry (Pilgrim) on Jan 10, 2003 at 23:44 UTC

    Actually, Apache under NT4 will allow you to use a shebang in the form of:

    #!Perl/bin/perl

    In other words, you don't need the drive letter if Apache and Perl are on the same drive and NT understands back and forward slashes in paths.

    It also helps if you install Perl in a directory called "usr" instead of the default "Perl" so that you don't need to edit the shebang when you upload the script to a UNIX server. ;)

    I wish someone had told me that before I installed it. :/

    Oh, and the registry option does work, which is handy for running scripts on the command line.

      Apache under windows uses the #! line, if a drive letter is ommited it assumes the same drive that apache is installed in, otherwise you need to specify it as in #!d:/perl/bin/perl When I used to install perl/apache on windows I would:
      1. install apache in the default dir "C:\Program Files\Apache" folder.
      2. run apache's command to register service, set start mode for the service to automatic.
      3. install perl in c:\usr
      That way apache runs on every boot, and when you type #!/usr/bin/perl, in a script it just works!
Re: How does apache under NT find the perl interpreter?
by Anonymous Monk on Oct 01, 2000 at 00:38 UTC
    It depends on your webserver software: Apache uses the shebang notation (the #! line). Most other webservers let you define the location of the perl executable in their preferences.

      Is this the only way available? How can one configure apache not to do this?

      Background to the question: sometimes you need to migrate whole sets of CGI scripts from a Unix box to a Win32 box, e.g., to a demo laptop. Now, imagine on that Unix box perl was in /usr/local/bin/perl - well, you won't have that one on your Win32 box. What to do now apart from changing the interpreter location in every script?

      The only solution I know of is copying the perl interpreter and some other files (DLLs) to a new directory /usr/local/bin, and then setting the PERL5LIB environment variable in the apache config with a SetEnv directive for the CGI directory, because otherwise the interpreter will not find its libraries, as the ActivePerl binary of perl has @INC compiled in as ".". Someone else suggested to modify the registry entry for the binary to avoid the SetEnv part, but the principal problem stays the same.

      BTW, in IIS, you can configure which interpreter is used based on the extension of the script - the usual Win32 way of deciding this. Is there anything like this in apache?

      Christian Lemburg
      Brainbench MVP for Perl
      http://www.brainbench.comh

        I work with two fix systems: one win32 with Perl in C:/Perl/bin/perl and several identically built linuxes with Perl in /usr/bin/perl and if I have to migrate serveral scripts from on system to the other, I open all scripts in Phase 5, my favourite html-editor on win32 and do a search and replace on the shebang over all opened files.
        Alternatively you could always write a short search and replace script, that changes the shebang-line accordingly.

         
        neophyte
Re: How does apache under NT find the perl interpreter?
by shadox (Priest) on Jun 20, 2001 at 01:00 UTC
    Lets say you have perl in C:\perl\bin\perl
    then your script should start like this

    --------------------------------------

    #!C:\perl\bin\perl

Re: How does apache under NT find the perl interpreter?
by ajt (Prior) on Sep 21, 2001 at 16:47 UTC
    Apache does indeed use a shebang notation, and in 1.3.something (?12) and above can read from the Windows Registry and work out where Perl is.

    I must admit I use the shebang method, so I can't confirm that registry reading works.