Apache (2) 抛出“没有这样的文件或目录:执行‘/usr/lib/cgi-bin/fst.cgi’”失败”

发布于 2024-12-11 14:32:50 字数 817 浏览 0 评论 0 原文

我正在 Ubuntu 10.10 (Maverick Meerkat) 中工作,并在 CGI 脚本http://en.wikipedia.org/wiki/Apache_HTTP_Server" rel="noreferrer">Apache,但它向我显示以下错误...

[周六错误没有这样的文件或目录:执行“/usr/lib/cgi-bin/fst.cgi”失败 [Sat Oct 22 02:56:45 2011] [错误] [客户端 127.0.0.1] 脚本标头过早结束:fst.cgi

我的脚本是

#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "hello world";

我已经设置了文件的权限...

我还添加了以下行在文件 apache.conf 中:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory /usr/lib/cgi-bin/>
   Options +ExecCGI
</Directory>

AddHandler cgi-script .cgi .pl

但它仍然向我显示相同的错误。我已经做了所有可能的改变,但没有取得任何成功......

I am working in Ubuntu 10.10 (Maverick Meerkat) and running my CGI script under Apache, but it is showing me the following error...

[Sat errorNo such file or directory: exec of '/usr/lib/cgi-bin/fst.cgi' failed
[Sat Oct 22 02:56:45 2011] [error] [client 127.0.0.1] Premature end of script headers: fst.cgi

My script is

#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "hello world";

I have set the permissions of the file...

I have also added the following line in file apache.conf:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory /usr/lib/cgi-bin/>
   Options +ExecCGI
</Directory>

AddHandler cgi-script .cgi .pl

But still it is showing me the same error. I have done all the possible changes, but I didn't get any success...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

可是我不能没有你 2024-12-18 14:32:50

我在 /var/log/apache2/error_log 中遇到了相同的错误。
我终于意识到Perl脚本是直接从我的Windows系统(通过Parallels虚拟机)复制的,而且似乎Windows的回车符“\r\n”导致了这个错误。

当我使用 ASCII 模式将此 Perl 脚本从 Windows FTP 到 Mac 时
自动将“\r\n”转换为“\r”,
相同的 Perl 脚本无需任何修改即可正常工作。

I encountered the same error found in my /var/log/apache2/error_log.
I finally realized that the Perl script was directly copied from my Windows system (via Parallels virtual machine) and it seems that the Windows' carriage return "\r\n" causes this error.

When I FTP this Perl script from Windows to Mac using ASCII mode
to automatically convert "\r\n" into "\r",
the same Perl script works correctly without any modification.

咿呀咿呀哟 2024-12-18 14:32:50

错误消息“没有这样的文件或目录”既不是来自 Apache,也不是来自 Perl。当 Apache 调用脚本时,它将执行传递给系统的命令行解释器 (CLI)。此 CLI 打开脚本文件并读取第一行“#!/usr/bin/perl”(shebang 行)。

正如 Sam Tseng 所阐述的,该文件显然包含一个 Windows 换行字符序列:“\r\n”(十六进制代码:x0D x0A,符号:CR LF)。现在 CLI 解释器会读取该行直到“\n”字符。 CLI 无法识别“\r”字符,因此它成为路径“/usr/bin/perl \r”的一部分,并且不再是换行符的一部分。

为什么选项“-w”可以解决此问题?

当您添加选项“-w”时,字符“\r”将成为参数“-w\r”的一部分。现在可以找到 Perl 可执行文件的路径“/usr/bin/perl”,并且“-w\r”作为命令行参数传递。然而,Perl 很好,在处理“-w\r”选项时不会导致错误。

The error message "No such file or directory" doesn't come from Apache nor from Perl. When Apache is invoking the script, it passes the execution to the command line interpreter (CLI) of the system. This CLI opens the script file and reads the first line "#!/usr/bin/perl" (shebang line).

As Sam Tseng has elaborated, the file obviously contains a Windows line break character sequence: "\r\n" (hexcode: x0D x0A, symbols: CR LF). Now the CLI interpreter reads the line until the "\n" character. The CLI doesn't recognice the "\r" character, so it becomes part of the path "/usr/bin/perl \r" and is not anymore part of the line break.

Why does the option '-w' fix this issue?

When you add the option '-w' than the character '\r' becommes part of the argument "-w\r". The path to the Perl executable can now be found "/usr/bin/perl" and "-w\r" is passed as command line argument. However, Perl is nice and doesn't cause errors when handling the "-w\r" option.

寂寞美少年 2024-12-18 14:32:50

我多次遇到同样的问题 - 尝试将文件中的 shebang 修改为:

#!/usr/bin/perl -w

现在为什么这会使脚本执行,这让我很困惑......如果您发现了,请也告诉我们。

I encountered the same problem several times - try to modify your shebang in the file to:

#!/usr/bin/perl -w

Now why this makes the script execute, beats me ... if you find out please let us know also.

千秋岁 2024-12-18 14:32:50

您需要删除在 Windows 环境中创建文件时产生的“Windows 回车符”。

这可以通过命令轻松完成。

dos2unix fst.cgi fst.cgi

第一个 fst.cgi 是要转换的文件,第二个是目标文件名,可以保持不变。

下一步是运行命令,

 chmod 755 fst.cgi

这将覆盖文件的权限并允许您执行该文件。

祝你好运

You need to remove the "Windows' carriage return" which is produced when files are created inside a Windows environment.

this can be easily done by the command

dos2unix fst.cgi fst.cgi

The first fst.cgi is the file you want to convert and the second is the destination file name, which can remain the same.

Next step is to run the command

 chmod 755 fst.cgi

This will override the permission of the file and allow you to execute the file.

Good luck

最美的太阳 2024-12-18 14:32:50

我遇到了类似的错误:(2)没有这样的文件或目录:'/var/www/cgi-bin/aaa.py' 的 exec 失败。像上面这样的答案无法解决。然后我发现: vim aaa.py :set ff 并且文件格式是dos。 :set ff=unix 和 wq 很快修复了它。

I encountered a Similar error : (2)No such file or directory: exec of '/var/www/cgi-bin/aaa.py' failed. And answers like Above can not be resolved.Then I find that : vim aaa.py :set ff and the fileformat is dos. :set ff=unix and wq soon fixed it.

入画浅相思 2024-12-18 14:32:50
  • 确保您的脚本在 apache 用户下正常执行: # su -c /usr/lib/cgi-bin/fst.cgi apache
  • 确保目录 /usr/lib/cgi-bin< /code> 有 755 权限
  • 确保脚本 /usr/lib/cgi-bin/fst.cgi 有 755 权限
  • Make sure your script executes OK under apache user: # su -c /usr/lib/cgi-bin/fst.cgi apache
  • Make sure the directory /usr/lib/cgi-bin has 755 permission
  • Make sure the script /usr/lib/cgi-bin/fst.cgi has 755 permission
本王不退位尔等都是臣 2024-12-18 14:32:50

同样的问题花了我几乎一整天的时间!我想提供一种可能性。

我的电脑和远程服务器操作系统都是Ubuntu 16.04。我正在使用 FileZilla 将文件从 PC 传输到远程服务器。 默认传输类型设置为自动,这就是我的情况的原因。

解决方案是将默认传输类型设置为二进制。导航路径是:
编辑 -> 首选项 -> 设置 -> 转账 -> 文件类型 -> 默认传输类型:

The same problem costs me almost a whole day! I would like to provide a possibility.

Both my PC and remote server OS is Ubuntu 16.04. And I am using FileZilla to transfer files from the PC to the remote server. The default transfer type is set as Auto which is the reason in my case.

The solution is that set the default transfer type as Binary. And the navigation path is:
Edit -> Preferences -> Settings -> Transfers -> File Types -> Default transfer type:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文