A. Stoica: Problem mit Perl unter Apache

Hi,

Wenn ich bei gestartetem Webserver versuche ein Perl-Script im Browser zu starten erhalte ich den "Speichern unter..." Dialog anstatt einer Ausgabe im Browser. Wenn ich ein Perl-Script per Doppelklick starte oder im "Speichern unter..." Dialog "Öffnen" auswähle, startet das Script wie erwartet in einer Dos-Box.

Wer kann mir erklären, woran das liegen mag? Vielen Dank schon mal im voraus... Alex

Ordnerstruktur (Windows):

c:/Apache
c:/Apache/Apache --> "Apache 1.3.24"
c:/Apache/Htdocs --> "Webseiten"
c:/Apache/Htdocs/Cgi-bin --> "Scriptordner"
c:/Apache/Perl --> "ActiveState Perl 5.6.1"

Test Script mit Shebang Variationen:

#!/usr/bin/perl
#!c:/apache/perl/bin/perl.exe
#!c:/apache/perl/bin/perl
#!c:/apache/perl/bin

##  printenv -- demo CGI program which just prints its environment

print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\n|g;
    $val =~ s|"|\"|g;
    print "${var}="${val}"\n";
}

Httpd.conf (Ausschnitt):

...

ServerName localhost

DocumentRoot: The directory out of which you will serve your

documents. By default, all requests are taken from this directory, but

symbolic links and aliases may be used to point to other locations.

DocumentRoot "C:/Apache/Htdocs"

Each directory to which Apache has access, can be configured with respect

to which services and features are allowed and/or disabled in that

directory (and its subdirectories).

First, we configure the "default" to be a very restrictive set of

permissions.

<Directory "C:/Apache/Htdocs">
    Options All
    AllowOverride None
</Directory>

Note that from this point forward you must specifically allow

particular features to be enabled - so if something's not working as

you might expect, make sure that you have specifically enabled it

below.

This should be changed to whatever you set DocumentRoot to.

<Directory "C:/Apache/Htdocs">

This may also be "None", "All", or any combination of "Indexes",

"Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".

Note that "MultiViews" must be named *explicitly* --- "Options All"

doesn't give it to you.

Options Indexes FollowSymLinks MultiViews Includes ExecCGI

This controls which options the .htaccess files in directories can

override. Can also be "All", or any combination of "Options", "FileInfo",

"AuthConfig", and "Limit"

AllowOverride None

Controls who can get stuff from this server.

Order allow,deny
    Allow from all
</Directory>

...

Apache parses all CGI scripts for the shebang line by default.

This comment line, the first line of the script, consists of the symbols

pound (#) and exclamation (!) followed by the path of the program that

can execute this specific script.  For a perl script, with perl.exe in

the C:\Program Files\Perl directory, the shebang line should be:

#!c:/apache/perl/bin/perl

Note you _must_not_ indent the actual shebang line, and it must be the

first line of the file.  Of course, CGI processing must be enabled by

the appropriate ScriptAlias or Options ExecCGI directives for the files

or directory in question.

However, Apache on Windows allows either the Unix behavior above, or can

use the Registry to match files by extention.  The command to execute

a file of this type is retrieved from the registry by the same method as

the Windows Explorer would use to handle double-clicking on a file.

These script actions can be configured from the Windows Explorer View menu,

'Folder Options', and reviewing the 'File Types' tab.  Clicking the Edit

button allows you to modify the Actions, of which Apache 1.3 attempts to

perform the 'Open' Action, and failing that it will try the shebang line.

This behavior is subject to change in Apache release 2.0.

Each mechanism has it's own specific security weaknesses, from the means

to run a program you didn't intend the website owner to invoke, and the

best method is a matter of great debate.

To enable the this Windows specific behavior (and therefore -disable- the

equivilant Unix behavior), uncomment the following directive:

ScriptInterpreterSource registry

The directive above can be placed in individual <Directory> blocks or the

.htaccess file, with either the 'registry' (Windows behavior) or 'script'

(Unix behavior) option, and will override this server default option.

...

Alias /root/ "C:/Apache/Htdocs/"

<Directory "C:/Apache/Htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

#
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #

ScriptAlias /cgi-bin/ "C:/Apache/Htdocs/cgi-bin/"
 ScriptAlias /pl/ "C:/Apache/Htdocs/cgi-bin/"

#
    # "C:/Apache/Apache/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    #
     <Directory "C:/Apache/Htdocs/cgi-bin">
 AllowOverride None
 Options  ExecCGI
 Order allow,deny
        Allow from all
     </Directory>

</IfModule>

End of aliases.

...

# AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
    #
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    #
    # To use CGI scripts:
    #

AddHandler cgi-script .cgi .pl
    Action application/x-httpd-cgi /perl/perl.exe

...

  1. hallo Alex,

    Wer kann mir erklären, woran das liegen mag? Vielen Dank schon mal im voraus...

    ohje, schön viel posting-text  -  aber besser als zuwenig ;-)

    c:/Apache/Perl --> "ActiveState Perl 5.6.1"

    das ist zumindest ungewöhnlich, kann aber funktionieren, wenn deine perl.exe im %path% liegt

    #!/usr/bin/perl
    #!c:/apache/perl/bin/perl.exe
    #!c:/apache/perl/bin/perl
    #!c:/apache/perl/bin

    und das ist _stark_ revisionsbedürftig. Bei deiner Ordnerstruktur _kann_ deine shebang nur heißen:
       #!c:/apache/perl/bin/perl.exe -w
    und nicht mehr!

    Httpd.conf (Ausschnitt):
    ScriptInterpreterSource registry

    wenn du diesen Eintrag auskommentiert (aktiviert) hast, brauchst du für lokalen Perl-Scripts gar keine "shebang" mehr, das ist der Zweck dieser Anweisung. Zu diesem Thema gabs hier im Forum bereits lebhafte Debatten.

    ScriptAlias /cgi-bin/ "C:/Apache/Htdocs/cgi-bin/"

    das mag korrekt sein

    ScriptAlias /pl/ "C:/Apache/Htdocs/cgi-bin/"

    und das ist einigermaßen unverständlich und gehört gestrichen.

    AddHandler cgi-script .cgi .pl

    das ist wieder korrekt

    Action application/x-httpd-cgi /perl/perl.exe

    und das ist nicht nötig

    Christoph S.

    1. hallo Alex,

      Wer kann mir erklären, woran das liegen mag? Vielen Dank schon mal im voraus...
      ohje, schön viel posting-text  -  aber besser als zuwenig ;-)

      man geht auf nummer sicher :o)~

      c:/Apache/Perl --> "ActiveState Perl 5.6.1"
      das ist zumindest ungewöhnlich, kann aber funktionieren, wenn deine perl.exe im %path% liegt

      eigentlich nicht ungewöhnlich, der pfad ist natürlich "c:\apache\perl" mit dem --> meinte ich eigentlich nur die perl version, die im ordner liegt, perl liegt im pfad und "perl -v" klappt auch...

      #!/usr/bin/perl
      #!c:/apache/perl/bin/perl.exe
      #!c:/apache/perl/bin/perl
      #!c:/apache/perl/bin
      und das ist _stark_ revisionsbedürftig. Bei deiner Ordnerstruktur _kann_ deine shebang nur heißen:
         #!c:/apache/perl/bin/perl.exe -w
      und nicht mehr!

      werd ich jetzt mal ausprobieren, bei falscher shebang line hatte ich sonst einen internal server error. mag aber auch an anderen dingen gelegen haben...

      Httpd.conf (Ausschnitt):
      ScriptInterpreterSource registry
      wenn du diesen Eintrag auskommentiert (aktiviert) hast, brauchst du für lokalen Perl-Scripts gar keine "shebang" mehr, das ist der Zweck dieser Anweisung. Zu diesem Thema gabs hier im Forum bereits lebhafte Debatten.

      ScriptAlias /cgi-bin/ "C:/Apache/Htdocs/cgi-bin/"
      das mag korrekt sein

      ScriptAlias /pl/ "C:/Apache/Htdocs/cgi-bin/"
      und das ist einigermaßen unverständlich und gehört gestrichen.

      diese zeile habe ich von: http://www.christian-bieser.net/wamp_perl2.html

      AddHandler cgi-script .cgi .pl
      das ist wieder korrekt

      Action application/x-httpd-cgi /perl/perl.exe
      und das ist nicht nötig

      habe ich mir schon gedacht...

      vielen dank für die schnelle antwort, hoffe jetzt funzt es mal, hab zwei nachmittage probiert und im netz gesucht, apache hoch und wieder runter fahren kann ganz schön nervig sein... melde mich nachher noch mal...

      alex (ebenfalls berliner)

      1. hallo Alex,

        bei falscher shebang line hatte ich sonst einen internal server error. mag aber auch an anderen dingen gelegen haben...

        ja, unbedingt, weil in deiner httpd.conf

        ScriptInterpreterSource registry

        drinsteht. Das heißt, der Apache sucht nach der perl.exe nicht unter Berücksichtigung der shebang, sondern unter Berücksichtigung deiner registry

        diese zeile habe ich von: http://www.christian-bieser.net/wamp_perl2.html

        hm. Hab mir die Seite mal angeschaut. Steht viel Richtiges drin, aber mit solchen einzelnen Hinweisen eben auch einiges, was nicht stimmt

        hab zwei nachmittage probiert und im netz gesucht

        und dabei bist du tatsächlich nicht auf http://aktuell.de.selfhtml.org/artikel/server/apacheconf/index.htm gestoßen ?

        Im übrigen: hast du dir denn mal deine Apche-Logs angeschaut?

        Christoph S.

      2. #!c:/apache/perl/bin/perl.exe -w

        habs damit probiert = klappt nicht :o(

        ScriptInterpreterSource registry

        habs damit ebenfalls probiert = klappt nicht :o(

        kann doch nicht so schwer sein, hab schon zig tutorials durch wie man perl mit apache einsetzt und trotzdem kommt immer der "Speichern unter..." Dialog, ich habe sogar kopien von funktionierenden *.conf dateien gehabt und zeile für zeile durch (???)... so langsam zweifle ich an mir selbst, OpenSSL läuft und PHP läuft doch auch...

        ich wechsel mal probehalber die distribution von active state gegen die von apache.org, vielleicht klappts mit mod_perl

        alex

        1. Hi alex,

          trotzdem kommt immer der "Speichern unter..."
          Dialog,

          vielleicht solltest Du mal langsam die wichtigen
          Informationen angeben. Der "Speichern"-Dialog kann
          nämlich ganz verschiedene Ursachen haben - und ganz
          unterschiedliche Ergebnisse produzieren.

          Fangen wir doch mal damit an, daß Du das, was das
          übermittelt wurde, tatsächlich speicherst und uns
          dann erzählst, was es ist!

          Mir fallen spontan zwei Möglichkeiten ein:

          a) Es ist der Quelltext Deines Skripts.
             Dann ist die CGI-Konfiguration im Apache falsch;
             über das Skript läßt sich noch nichts aussagen.

          b) Es ist die Ausgabe Deines Skripts.
             Dann ist die CGI-Konfiguration im Apache richtig;
             das Skript sendet aber vermutlich einen MIME-Typ,
             den Dein Browser zum Anlaß nimmt, die Seite nicht
             anzuzeigen, sondern zum Speichern anzubieten.

          ich wechsel mal probehalber die distribution von
          active state gegen die von apache.org, vielleicht
          klappts mit mod_perl

          Oh weh. Bloß nicht!

          Soweit ich das glaube verstanden zu haben, erfordert
          mod_perl, daß Du Deinen Programmierstil radikal änderst. Heb Dir das mal für später auf.

          Ich tippe mit hoher Wahrscheinlichkeit, daß das Problem
          vom Perl-Interpreter selbst nicht abhängig ist, sondern
          immer noch an der Apache-Konfiguration liegt.

          Viele Grüße
          <img src="http://www.schroepl.net/projekte/gzip_cnc/gzip_cnc.gif" border=0 alt=""> Michael

    2. Hallo Christoph,

      c:/Apache/Perl --> "ActiveState Perl 5.6.1"
      das ist zumindest ungewöhnlich, kann aber
      funktionieren, wenn deine perl.exe im %path% liegt

      ich sehe bei keinem der nachfolgenden Versuche irgend
      ein Anzeichen davon, daß der %path% eine Rolle spielen
      könnte:

      #!/usr/bin/perl
      #!c:/apache/perl/bin/perl.exe
      #!c:/apache/perl/bin/perl
      #!c:/apache/perl/bin
      und das ist _stark_ revisionsbedürftig. Bei deiner Ordnerstruktur _kann_ deine shebang nur heißen:
         #!c:/apache/perl/bin/perl.exe -w
      und nicht mehr!

      _Falls_ der %path% passen würde, könnte sie auch

      #!perl -w

      heißen.

      ScriptAlias /cgi-bin/ "C:/Apache/Htdocs/cgi-bin/"
      das mag korrekt sein

      Wenn schon ein eigenes CGI-Verzeichnis, dann fände
      ich es außerhalb des sonstigen URL-Raums schöner.

      ScriptAlias /pl/ "C:/Apache/Htdocs/cgi-bin/"
      und das ist einigermaßen unverständlich und gehört
      gestrichen.

      Das ist gar nicht "unverständlich".
      Es ist einfach ein weiteres CGI-Verzeichnis, dem der
      Besucher nicht am URL ansehen soll, daß es eines ist.

      AddHandler cgi-script .cgi .pl
      das ist wieder korrekt

      Überflüssig. Weg damit.

      Das würde innerhalb des gesamten URL-Raums eine
      Verknüpfung des CGI-Handlers mit diesen beiden
      Endungen bringen. Um aber zu funktionieren, ist es
      zuwenig (da muß noch das "Options" hinzu"), und
      nötig ist es auch nicht, weil das /cgi-bin/ ja
      bereits mit ScriptAlias vollständig definiert ist.

      Action application/x-httpd-cgi /perl/perl.exe
      und das ist nicht nötig

      Sehr interessant. Habe ich noch nie gesehen.
      Ist aber eine legale Alternative zum AddHandler.

      Nötig sind hier beide nicht.
      ScriptAlias macht alles, was man braucht.

      Viele Grüße
      <img src="http://www.schroepl.net/projekte/gzip_cnc/gzip_cnc.gif" border=0 alt=""> Michael