[英]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?
怎么了?
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.