Apache(2)抛出“没有这样的文件或目录:exec of '/usr/lib/cgi-bin/fst。cgi的失败”

时间:2021-11-21 12:13:08

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

我在Ubuntu 10.10 (Maverick Meerkat)工作,并在Apache下运行我的CGI脚本,但是它显示了以下错误……

[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

[Sat errorNo这样的文件或目录:exec of '/usr/lib/cgi-bin/fst。cgi的失败[Sat 10月22日02:56:45][错误][客户127.0.0.1]过早结束脚本头: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:

我还在文件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...

但它还是显示了同样的错误。我已经做了所有可能的改变,但我没有取得任何成功…

6 个解决方案

#1


26  

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.

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

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.

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

#2


9  

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).

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

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.

正如Sam Tseng所阐述的,该文件显然包含了一个Windows断行字符序列:“\r\n”(hexcode: x0D x0A,符号:CR LF)。现在,CLI解释器读取一行直到“\n”字符。CLI没有识别“\r”字符,因此它成为path“/usr/bin/perl \r”的一部分,不再是换行符的一部分。

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

为什么选项“-w”解决了这个问题?

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.

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

#3


8  

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.

为什么这让脚本执行,打败我…如果你发现了,请告诉我们。

#4


1  

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.

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

#5


0  

  • Make sure your script executes OK under apache user: # su -c /usr/lib/cgi-bin/fst.cgi apache
  • 确保您的脚本在apache用户下面执行:# su -c /usr/lib/cgi-bin/fst。cgi apache
  • Make sure the directory /usr/lib/cgi-bin has 755 permission
  • 确保目录/usr/lib/cgi-bin有755权限。
  • Make sure the script /usr/lib/cgi-bin/fst.cgi has 755 permission
  • 确保脚本/usr/lib/cgi-bin/fst。cgi有755个许可

#6


0  

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

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

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.

第一个置。cgi是您想要转换的文件,第二个是目标文件名,它可以保持不变。

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

祝你好运

#1


26  

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.

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

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.

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

#2


9  

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).

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

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.

正如Sam Tseng所阐述的,该文件显然包含了一个Windows断行字符序列:“\r\n”(hexcode: x0D x0A,符号:CR LF)。现在,CLI解释器读取一行直到“\n”字符。CLI没有识别“\r”字符,因此它成为path“/usr/bin/perl \r”的一部分,不再是换行符的一部分。

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

为什么选项“-w”解决了这个问题?

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.

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

#3


8  

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.

为什么这让脚本执行,打败我…如果你发现了,请告诉我们。

#4


1  

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.

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

#5


0  

  • Make sure your script executes OK under apache user: # su -c /usr/lib/cgi-bin/fst.cgi apache
  • 确保您的脚本在apache用户下面执行:# su -c /usr/lib/cgi-bin/fst。cgi apache
  • Make sure the directory /usr/lib/cgi-bin has 755 permission
  • 确保目录/usr/lib/cgi-bin有755权限。
  • Make sure the script /usr/lib/cgi-bin/fst.cgi has 755 permission
  • 确保脚本/usr/lib/cgi-bin/fst。cgi有755个许可

#6


0  

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

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

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.

第一个置。cgi是您想要转换的文件,第二个是目标文件名,它可以保持不变。

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

祝你好运