嗨,因为关于这个主题的其他帖子并没有给我太多的正义(他们似乎都没有申请 Ubuntu 13.10,我运行的 Ubuntu 版本),我决定再做一个。运行这些行之后(stackoverflow 成员建议运行这些行)..
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/cgi.load .
sudo ln -s ../mods-available/cgid.load .
sudo service apache2 restart
我将 cgi 文件(它们是 perl 文件)放入了我的 Apache2 的 cgi-bin @/usr/lib/cgi-bin。输入 localhost/cgi-bin/test.cgi 时,我收到 500 内部服务器错误。这就是服务器错误日志所说的..
[Fri Nov 22 21:23:29.045785 2013] [cgi:error] [pid 9559] [client 127.0.0.1:47663] AH01215: (8)Exec 格式错误:'/usr/lib/cgi-bin/test .cgi' 失败
[Fri Nov 22 21:23:29.046720 2013] [cgi:error] [pid 9559] [client 127.0.0.1:47663] 头文件前的脚本输出结束:test.cgi
test.cgi 看起来像这样...
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print <<HTML;
<html>
<head>
<title>A Simple Perl CGI</title>
</head>
<body>
<h1>A Simple Perl CGI</h1>
<p>Hello World</p>
</body>
HTML
exit;
有谁知道发生这种情况时该怎么办或有任何建议?谢谢
编辑::奇怪的是,我得到了这个 cgi 文件,我调用 test2.cgi 来运行。
#!/usr/bin/perl
use strict;
use warnings;
sub main {
print "Content-type: text/html\n\n";
print "Hello world\n\n";
print "What's your favorite food brah?\n";
}
main();
但是我需要处理的更大、更高级的 cgi 文件无法运行。这些包括在 html 标签中打印出来的东西。
编辑:忽略代码中任何奇怪的间距。这就是我将其复制到帖子中的方式。
最佳答案
编辑:不清楚每行开头的原始代码中是否有额外的空格导致此问题,如果没有,请忽略其余部分!谢谢阿蒙
如果您尝试从控制台运行它们,它将有助于立即查看任何错误。在这种情况下...
Can't find string terminator "HTML" anywhere before EOF
#!/usr/bin/perl # make sure no space before # and this comment is not here
print "Content-type: text/html\n\n";
print <<HTML;
<html>
....
</body>
HTML
exit; # Make sure the HTML line before this has nothing either side of it
基本上,删除 #!/usr/bin/perl 行之前的单个空格,因为 Amon 指出它是否存在,并且结束的 HTML 行也应该修复它(heredoc 终止符周围不应该有任何东西,它在那里并不明显每行开头都有空格,但有)。
有时在网站上放置示例代码时,可能会引入空格等以提供视觉帮助。我猜这里引入了一些被复制到代码中的东西。很难发现!
关于perl - 尝试在 Apache 2.4.6 Ubuntu 13.10 上运行 perl cgi 文件时出现 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20157826/