我花了几个小时试图修复perl程序上的内部服务器错误。我把程序提炼到最简单的,什么都行不通。实际上,这是整个程序:
#!/usr/local/bin/perl
use strict;
print "Content-type: text/htmlnn";
print <<"thepage";
<html><head><title>Test</title></head><body>
<p>help</p>
</body></html>
thepage
无法让它工作。权限正确。同一个目录,我实际上有一百个其他脚本不断运行。httpd.conf fine.当 SSH 进入服务器时,它从命令行运行。错误消息说:
[Mon May 18 09:59:29 2020] [error] [client 98.190.183.148] (13)Permission denied: exec of '/data/www/facialsurgery/root/cgi-bin/test_print_2.pl' failed
[Mon May 18 09:59:29 2020] [error] [client 98.190.183.148] Premature end of script headers: test_print_2.pl
但我修好了!通过在 shebang 行中添加 "-w",因此该行表示:
#!/usr/local/bin/perl -w
但是,正如我所提到的,我有很多程序在没有 -w 的情况下运行良好。 我能做些什么来更多地追踪这个问题,这样我最终就不会在更重要的程序中遇到更多麻烦?非常感谢您对此的任何见解。
错误:
(13)Permission denied: exec of '/data/www/facialsurgery/root/cgi-bin/test_print_2.pl' failed
这意味着 Web 服务器 (Apache( 由于权限错误而无法执行脚本。(13
是Permission denied
的错误号。这与-w
的存在与否无关。[1]
首先,确定 Web 服务器 (Apache( 以哪个用户身份运行。对于本文的其余部分,我将假设它是默认值,www-data
。
然后,确保以下文件可由www-data
用户(或其组(读取(授予r
权限(和可执行(x
(:
/data/www/facialsurgery/root/cgi-bin/test_print_2.pl
这包括确保以下目录可由www-data
用户(或其组(访问(x
(:
/data/www/facialsurgery/root/cgi-bin
/data/www/facialsurgery/root
/data/www/facialsurgery
/data/www
/data
如果这些权限没有问题,您也可能遇到冲突或卷范围的限制(例如noexec
属性值(或其他安全措施(例如 SELinux 限制(
- 我认为古代系统过去将shebang(
#!
(之后的所有内容视为要执行的命令。在这样的系统上,内核将尝试执行不存在的文件/usr/local/bin/perl -w
。但这会导致错误2
(No such file or directory
(,我不相信任何现代系统会这样做。