当我尝试访问我的Perl脚本时,Windows上的Apache给出了以下错误:
Server error! The server encountered an internal error and was unable to complete your request. Error message: End of script output before headers: sample.pl If you think this is a server error, please contact the webmaster. Error 500 localhost Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.3
这是我的示例脚本
#!"C:\xampp\perl\bin\perl.exe" print "Hello World";
但不是在浏览器上工作
在raspberry-pi上发生了相同的错误。我通过添加-w
shebang来修复它
#!/usr/bin/perl -w
可能这是SELinux块。尝试这个:
# setsebool -P httpd_enable_cgi 1
# chcon -R -t httpd_sys_script_exec_t cgi-bin/your_script.cgi
备查:
这通常是您无法查看或执行文件时发生的错误,其原因通常是权限错误.我将首先关注@Renning的建议并运行chmod 755 test.cgi
(显然用这里的cgi脚本替换test.cgi).
如果这不起作用,您可以尝试其他一些事情.当我test.cgi
在另一个用户的家中以root身份创建时,我曾遇到此错误.修复程序在那里运行chmod user:user test.cgi
,其中user是您所在的用户的名称.
我能想到的最后一件事是确保你的cgi脚本返回正确的标题.在我的ruby脚本中,我通过puts "Content-type: text/html"
在实际输出任何内容之前放入页面.
快乐的编码!
检查文件权限.
我在设置了错误权限的Linux机器上遇到了完全相同的错误.
chmod 755 myfile.pl
解决了这个问题.
如果这是Web的CGI脚本,那么您必须输出标题:
#!"C:\xampp\perl\bin\perl.exe"
print "Content-Type: text/html\n\n";
print "Hello World";
以下错误消息告诉您这一点 End of script output before headers: sample.pl
或者甚至更好,使用CGI模块输出标题:
#!"C:\xampp\perl\bin\perl.exe"
use strict;
use warnings;
use CGI;
print CGI::header();
print "Hello World";