【问题标题】:How do I run Perl files over XAMPP on Windows?如何在 Windows 上通过 XAMPP 运行 Perl 文件?
【发布时间】:2011-12-13 04:59:06
【问题描述】:

我是 Perl 语言的新手,我尝试像处理 PHP 文件一样运行它,将文件放在 htdocs 中,然后通过 localhost 访问它们。

以下是我创建的 Perl 文件,但无法在 localhost 上运行:

-----你好.pl-------------

   #!/usr/bin/perl
   print "Hello World.\n";

【问题讨论】:

    标签: perl apache xampp wamp


    【解决方案1】:

    首先修复“shebang”行以指向您的 Perl 可执行文件(我使用 WampDeveloper,而不是 XAMPP,因此您的路径会有所不同)...

    #!C:/WampDeveloper/Tools/Perl/perl/bin/perl.exe
    print "Hello World.\n";
    

    然后在 DocRoot 中创建一个“cgi-bin”目录并将您的 Perl 脚本放入其中。

    在这个目录中也创建一个 .htaccess 文件,里面有这个...

    DefaultType text/html
    Options -Indexes +ExecCGI
    SetHandler cgi-script
    

    转到网址:http://www.example.com/cgi-bin/perlscript.pl

    注意:这假设上述目录在主 Apache 配置中没有为它禁用 htaccess 选项。

    【讨论】:

      【解决方案2】:

      如果您的 PHP 安装有 Perl 模块,您可以直接从 PHP 评估 Perl 代码。

      <?php
          print "Hello from PHP!";
          $perl = new Perl();
          $perl->require("test1.pl");
          print "Bye!";
      ?>
      

      【讨论】:

      • 否则你可以通过 CGI 设置 apache 使用 perl
      【解决方案3】:
      1. 安装 xampp。在安装过程中,请确保您已检查要安装的 perl。
      2. 我认为,您已将 xampp 安装在 c:/xampp 目录中。
      3. 现在转到 c:/xampp/htdocs 目录。在 htdocs 目录中创建一个目录 perl。现在在 perl 目录中,创建一个名为 hello.cgi 的文件。
      4. 在 hello.cgi 中编写以下代码 sn -p。

      你好世界程序:

      #!C:\xampp\perl\bin\perl.exe
      # The above line is perl execution path in xampp
      # The below line tells the browser, that this script will send html content.
      # If you miss this line then it will show "malformed header from script" error.
      print "Content-type: text/html\n\n";
      print "Hello world."
      

      现在从 xampp 控制面板启动 apache。并在浏览器的 url 中输入 localhost/perl/hello.cgi。

      【讨论】:

      • 我从这个答案中得到了帮助!
      【解决方案4】:

      请按以下步骤操作:

      1. 配置您的网络服务器以运行 Perl 脚本(您可以关注此网址以获取更多信息 http://editrocket.com/articles/perl_apache_windows.html)。

      2. 创建您的文件(perl 脚本)并将其保存在根 xampp 下的 cgi-bin 目录中。 (即:C:\xampp\cgi-bin)。

        N.B :您的文件应包含标头信息,例如 print "Content-type:text/html\r\n\r\n"; 在脚本顶部,这将有助于浏览器了解来自 Web 服务器的信息类型。

      3. 您的脚本应该有“shebang”行,否则服务器会抛出错误。

      【讨论】:

        猜你喜欢
        • 2011-09-23
        • 1970-01-01
        • 1970-01-01
        • 2020-07-19
        • 2019-10-31
        • 2014-02-16
        • 2018-08-07
        • 1970-01-01
        • 2021-07-16
        相关资源
        最近更新 更多