简体   繁体   English

打开文件句柄在mod_perl下不起作用ModPerl :: PerlRun

[英]Open filehandle not working under mod_perl ModPerl::PerlRun

I'm at my first attempt to use mod_perl. 我是第一次尝试使用mod_perl。 I'm totally new to it. 我是新手。 I opted for ModPerl::PerlRun because I don't want to make any modification to the scripts I already have 我选择了ModPerl::PerlRun因为我不想对已有的脚本进行任何修改

I followed the instructions in Installing Apache2/Modperl on Ubuntu 12.04 我按照在Ubuntu 12.04上安装Apache2 / Modperl中的说明进行操作

I uploaded script.pl to /perl , and the script looks like it's running fine except for this 我将script.pl上传到/perl ,除了该脚本,脚本看起来运行良好

open(my $fh, '<:encoding(UTF-8)', 'page_template.htm') or die $!;

It won't open the file and dies with the message 它不会打开文件并且死于消息

No such file or directory at /var/www/perl/script.pl

Update 更新

Note that the documentation for ModPerl::PerlRun has this to say 请注意, ModPerl::PerlRun的文档中有这样说

META: document that for now we don't chdir() into the script's dir, because it affects the whole process under threads. META:记录一下,目前我们不将chdir()放入脚本的目录,因为它会影响线程下的整个过程。

so it is probably not workable to simply do a chdir in your program's code, and the second option below should be used 因此,仅在程序代码中执行chdir可能不可行,应使用下面的第二个选项


Original* 原版的*

The current working directory of your CGI program isn't what you think. 您CGI程序的当前工作目录不是您所想的。 It is most likely to tbe the root directory / 它最有可能是根目录/

You can either use chdir to set the working directory of the script 您可以使用chdir设置脚本的工作目录

use File::Basename 'dirname';
chdir dirname(__FILE__);

or simply add the full path to the name of the file that you want to open, for instance 或仅将完整路径添加到要打开的文件的名称中,例如

open my $fh, '<:encoding(UTF-8)', '/perl/page_template.htm' or die $!;

Note that you can't use FindBin , as your program is being run as a subroutine of Apache's main mod_perl process, so $FindBin::Bin will be equal to the directory of the Apache executable httpd and not of your own program file 请注意,您不能使用FindBin ,因为您的程序是作为Apache主mod_perl进程的子例程运行的,因此$FindBin::Bin将等于Apache可执行文件httpd的目录,而不是您自己的程序文件的目录。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM