使用 apache
进行配置时和 perl cgi scripts
,不知道为什么index.cgi
/index.pl
显示为纯文本而不是执行它们。
当我把 http://localhost
在浏览器中它显示下面的代码,而不是执行它。
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 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 二进制位置。
AddHandler cgi-script .cgi .pl Options FollowSymLinks +ExecCGI
您的 httpd.conf 中还有一些错误/错误配置点
ScriptAlias /cgi-bin/ "D:\webserver\cgi-bin"
httpd.conf
.您应该更换您的 <Directory "D:\webserver">
与下面的部分。 <Directory "D:\webserver\cgi-bin" /> AddHandler cgi-script .cgi .pl Options FollowSymLinks +ExecCGI AllowOverride None </Directory>
perl test.cgi
cgi-bin
具有读写递归权限目录和你的 cgi 脚本。您还可以创建具有写入权限的目录或文件。如果不创建 cgi-bin
目录位于您可以拥有写入权限的其他位置,并在 alias
中提供其路径和 directory
httpd.conf
中的属性反而。 还有this link应该可以帮助你。
(额外评论,不是来自原始回答者:您可能还需要启用
cgi
模块。对我来说,让 cgi 在全新安装的 Apache 2 上工作的最后一步是 sudo a2enmod cgi
。在我这样做之前,该网站只是向我展示了脚本的内容。)
sudo a2enmod cgi
关于Perl Apache : Perl script displayed as plain text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14792978/