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

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

问题描述

同时用apacheperl cgi scripts配置,不知道为什么index.cgi/index.plcode> 显示为纯文本而不是执行它们.当我将 http://localhost 放在浏览器中时,它会显示在代码下方,而不是执行它.

列表项#!C:/Dwimperl/perl/bin/perl.exe -w打印内容类型:文本/html\n\n";打印<<头><title>一个 perl 网页</title><身体><h3>hello world 表单 perl</h3>HTML出口;

这是httpd.conf 文件的一部分,我大部分时间都编辑过(阅读各种在线参考资料、教程后)

# 这应该更改为您将 DocumentRoot 设置为的任何内容.<目录D:\webserver">听 80服务器名称本地主机:80LoadModule cgi_module modules/mod_cgi.so# 首先,我们将默认"配置为一组非常严格的# 特征.<目录/>选项 FollowSymLinks +ExecCGI允许覆盖无</目录>DirectoryIndex index.html index.html.var index.cgi index.pl访问文件名 .htaccess# 要在 ScriptAliased 目录之外使用 CGI 脚本:#(您还需要将ExecCGI"添加到Options"指令中.)##AddHandler cgi-script .cgi .plScriptAlias/cgi-bin/"C:/Apache/Apache2/cgi-bin/"

解决方案

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

<块引用>

 AddHandler cgi-script .cgi .pl选项 FollowSymLinks +ExecCGI

您的 httpd.conf 中还有一些错误/错误配置点

  • 别名行应该指向您的 cgi 脚本所在的 cgi-bin 目录.
<块引用>

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

  • 对于相同的 cgi-bin 目录,以下配置应该在 httpd.conf 中.您应该将 部分替换为以下内容.
<块引用>

<目录D:\webserver\cgi-bin"/>AddHandler cgi-script .cgi .pl选项 FollowSymLinks +ExecCGI允许覆盖无</目录>

  • 尝试从命令行运行您的 cgi 脚本,如下所示.它应该首先从命令行打印或运行.
<块引用>

perl test.cgi

  • 确保您对 cgi-bin 目录和您的 cgi 脚本具有读写递归权限.您还可以创建具有写入权限的目录或文件.如果没有在其他地方创建一个 cgi-bin 目录,您可以在其中拥有写入权限并在 aliasdirectory 属性中提供其路径httpd.conf 代替.
  • 每次遇到 apache conf 问题时,请检查 apache 错误日志以获取确切的错误消息.它会让您深入了解问题.

另外这个链接应该对你有帮助.

(额外评论,不是原回答者:您可能还需要启用 cgi 模块.对我来说,让 cgi 在一个Apache 2 的全新安装是 sudo a2enmod cgi.在我这样做之前,网站只是向我展示了脚本的内容.)

<块引用>

sudo a2enmod cgi

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;

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/"

解决方案

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

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

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

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

  • 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>

  • Try running your cgi script from command line like below. It should print or run from command line first.

perl test.cgi

  • 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.

(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天全站免登陆