当我尝试访问我的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";
但不能在浏览器上工作
如果这是一个网络的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";
检查文件权限。
我在Linux机器上设置了错误的权限时发生了完全相同的错误。
chmod 755 myfile.pl
解决了这个问题。
备查:
这通常是在您无法查看或执行文件时发生的错误,其原因通常是权限错误。 我将首先遵循@Renning的建议并运行chmod 755 test.cgi
(显然,在这里用你的cgi脚本的名字替换test.cgi)。
如果这不起作用,还有其他一些事情可以尝试。 当我在另一个用户的家中以root身份创建test.cgi
时,我曾经遇到这个错误。 修复那里是运行chmod user:user test.cgi
其中用户是您在家的用户的名称。
我能想到的最后一件事是确保你的cgi脚本返回正确的头文件。 在我的ruby脚本中,我实际上是在输出任何内容之前,先把puts "Content-type: text/html"
放入。
快乐的编码!
可能这是一个SELinux块。 尝试这个:
# setsebool -P httpd_enable_cgi 1 # chcon -R -t httpd_sys_script_exec_t cgi-bin/your_script.cgi
在覆盆子pi有相同的错误。 我通过向shebang添加-w
来修复它
#!/usr/bin/perl -w
如果使用Suexec,请确保脚本及其目录由您在suexec中指定的用户拥有。
另外,请确保运行cgi脚本的用户拥有对文件和shebang中指定的程序的权限执行权限。
例如,如果我的CGI脚本开始
#! /usr/bin/cgirunner
然后用户需要执行/ usr / bin / cgirunner的权限。
所以对于每个人开始用XAMPP CGI
改变扩展名从pl到cgi
将权限更改为755
mv test.pl test.cgi chmod 755 test.cgi
它也修理我的。
基于以上所有建议,我使用xampp来运行cgi脚本。 Windows 8的工作与任何变化,但Cent7.0它抛出这样的错误,如上所述
(2)没有这样的文件或目录:'/opt/lampp/cgi-bin/pbsa_config.cgi'的exec失败:/opt/lampp/cgi-bin/pbsa_config.cgi,referer:http:// <> /MCB_HTML/TestBed.html
[Wed Aug 30 09:11:03.796584 2017] [cgi:error] [pid 32051] [client XX:60624] header之前的脚本输出结束:pbsa_config.cgi,referer: http://xx/MCB_HTML/TestBed.html
尝试:
禁用selinux
给脚本的完全权限,但755会好的
我最后添加像-w像下面
#!/usr/bin/perl -w* use CGI ':standard'; { print header(), ... end_html(); } **-w** indictes enable all warnings.It started working, No idea why -w here.