Perl Apache:Perl脚本显示为纯文本 [英] Perl Apache : Perl script displayed as plain text

查看:202
本文介绍了Perl Apache:Perl脚本显示为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 apache perl cgi scripts 配置时,不知道为什么 .cgi / index.pl 显示为纯文本,而不是执行它们。
当我在浏览器中输入 http:// localhost 时,会显示以下代码,而不是执行它。

While configuring with apache and perl cgi scripts, don't know why index.cgi/index.pl are displayed as plain text instead of executing them. When I put http://localhost in browser it displays below code, instead of executing it.

List item
    #!C:/Dwimperl/perl/bin/perl.exe -w

     print "Content-type: text/html\n\n";
        print <<HTML;
        <html>
        <head>
        <title>A perl web page</title>
        </head>
        <body>
        <h3>A hello world form perl</h3>
        </body>

        HTML
        exit;

这是 httpd.conf 文件的一部分我已经编辑了大多数时间(阅读各种在线参考,教程后)

This are parts of httpd.conf file which I have edited most of the times (after reading various online reference, tutorials)

# This should be changed to whatever you set DocumentRoot to.
<Directory "D:\webserver">

Listen 80
ServerName localhost:80
LoadModule cgi_module modules/mod_cgi.so

# First, we configure the "default" to be a very restrictive set of 
# features.  
<Directory />
    Options FollowSymLinks +ExecCGI
    AllowOverride None
</Directory>

DirectoryIndex index.html index.html.var index.cgi index.pl

AccessFileName .htaccess

# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi .pl

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


推荐答案

当浏览器打印脚本代码时,意味着无法找到运行脚本的应用程序。下面两行应该是你解决这个问题的第一步。 AddHandler将确保以 .cgi .pl 结尾的文件被视为cgi脚本。并且 + ExecCGI 选项将允许执行脚本。还要确保你的脚本指向正确的perl二进制位置。

When browser is printing code of script that means it's unable to find the application to run the script. Below two lines should be your first steps to solve this. AddHandler will make sure files ending with .cgi and .pl to be treated as cgi scripts. And +ExecCGI option will allow to execute the script. Also make sure your script is pointing to correct perl binary location.


    AddHandler cgi-script .cgi .pl
    Options FollowSymLinks +ExecCGI


此外,您的httpd.conf中有一些错误/配置错误

Also There are some mistakes/misconfiguration points in your httpd.conf


  • 别名行应指向您的cgi脚本所在的 cgi-bin 目录。

  • Alias line should point to cgi-bin directory where your cgi scripts are present.

ScriptAlias / cgi-bin /D:\webserver\cgi-bin

ScriptAlias /cgi-bin/ "D:\webserver\cgi-bin"


  • 对于同样的cgi-bin目录,配置后应该在 httpd.conf 。您应该替换< Directory:D:\webserver> 部分。

  • For same cgi-bin directory following configuration should be in httpd.conf. You should replace your <Directory "D:\webserver"> part with below.

  • <Directory "D:\webserver\cgi-bin" />
        AddHandler cgi-script .cgi .pl
        Options FollowSymLinks +ExecCGI
        AllowOverride None  
    </Directory>
    





    • 尝试运行您的cgi脚本命令行如下。应先打印或从命令行运行。


    • perl test.cgi

      perl test.cgi




      • 确保您具有读写递归权限 cgi-bin 目录和您的cgi脚本。还可以创建具有写入权限的目录或文件。如果不在其他地方创建一个 cgi-bin 目录,您可以拥有写入权限,并在别名中提供它的路径
      • 检查apache错误。 c> 记录每次遇到apache conf问题时的确切错误消息。

        • Make sure you have read-write recursive permissions to cgi-bin directory and your cgi script. And also you can create directory or file with write permissions. If not create a cgi-bin directory at some other place where you can have write permissions and provide rather its path in alias and directory attributes in httpd.conf instead.
        • Check apache error log for exact error message every time you run into apache conf issues. It will give you good insight into the problem.
        • 此外,此链接应该可以帮助您。

          Also this link should help you.

          额外的评论,不是原始回答者:你可能还需要启用 cgi 模块对于我来说,最后一步是让cgi在全新安装的Apache 2上工作, sudo a2enmod在这之前,网站简单地向我展示了脚本的内容。)

          (Extra comment, not by the original answerer: You may also need to enable the cgi module. For me, the final step to getting cgi to work on a fresh install of Apache 2 was sudo a2enmod cgi. Before I did that, the website simply showed me the contents of the script.)


          sudo a2enmod cgi

          这篇关于Perl Apache:Perl脚本显示为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆