简体   繁体   English

如果 CGI 脚本以 #!/usr/bin/env perl 开头,则 HTTP 错误 404(未找到)

[英]HTTP Error 404 (Not Found) if the CGI script starts with #!/usr/bin/env perl

I have a CGI script whose content is not important.我有一个内容不重要的 CGI 脚本。 It works fine when executed from the web, but only if the first line is从 web 执行时它工作正常,但前提是第一行是

#!/usr/bin/perl -w

If I change it to如果我将其更改为

#!/usr/bin/env perl

...then I got HTTP Error 404 (Not found). ...然后我得到 HTTP 错误 404(未找到)。

When executed from the console, the script works properly in both cases.从控制台执行时,脚本在这两种情况下都能正常工作。 What is wrong?怎么了?


EDIT编辑

I solved my problem with adding the following lines at the beginning of my script:我通过在脚本开头添加以下行解决了我的问题:

#!/usr/bin/env perl

use lib '/usr/local/lib64/perl5';
use lib '/usr/local/share/perl5';
use lib '/usr/lib64/perl5/vendor_perl';
use lib '/usr/share/perl5/vendor_perl';
use lib '/usr/share/perl5';
use lib '/root/perl5/lib/perl5';

Obviously there is some problem with path, which I don't understand why, because when I execute script from the console, it works even without the use of use lib .显然路径存在一些问题,我不明白为什么,因为当我从控制台执行脚本时,即使不使用use lib它也可以工作。

I don't think the problems have anything to do with each other, or the solution actually solves anything.我认为这些问题之间没有任何关系,或者解决方案实际上可以解决任何问题。 If Apache can't find the script, it will still not be able to find it by adding the library paths.如果 Apache 找不到脚本,通过添加库路径仍然无法找到。 On the other hand, if there's any problem running the script the server would return a 500 status, not a 404. In every case, it's always the best to check the logs for the exact problem.另一方面,如果运行脚本有任何问题,服务器将返回 500 状态,而不是 404。在任何情况下,最好检查日志以找出确切的问题。

Your CGI environment probably has no PATH , or doesn't have /usr/bin/ in PATH , therefore env doesn't find perl.您的 CGI 环境可能没有PATH ,或者在PATH中没有/usr/bin/ ,因此env找不到 perl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到perl / cgi脚本错误404 apache2 - perl/cgi script not found error 404 apache2 / usr / bin / env perl可以作为命令运行,但不能在perl脚本中运行 - /usr/bin/env perl does work as command but not in perl script 如何覆盖usr bin env perl - How to override usr bin env perl 如何使用'#!/ usr / bin / env perl'- shebang在perl脚本中设置污点模式? - How do I set the taint mode in a perl script with a '#!/usr/bin/env perl'- shebang? 如何在使用'/ usr / bin / env perl'运行脚本时找出我正在使用的perl? - how to find out which perl I am using when running a script with '/usr/bin/env perl'? 如何将 /usr/bin/env perl 功能与 perl 参数一起使用? - How to use /usr/bin/env perl functionality along with perl arguments? 编写脚本时,#!/ usr / bin / perl和#!/ usr / bin / env perl有什么区别? - When scripting, what's the difference between #!/usr/bin/perl and #!/usr/bin/env perl? 错误:需要失败的依赖项 /usr/bin/perl - Error: failed dependencies /usr/bin/perl is needed Docker httpd apache 并让 cgi-bin 执行 perl 脚本 - Docker httpd apache and getting cgi-bin to execute perl script 如何允许perl cgi-bin脚本运行系统命令? - How to allow perl cgi-bin script to run system commands?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM