简体   繁体   中英

mod_perl handles inclusion paths differently than cgi?

I have a script that's written in perl, and executed as CGI. It works fine. Recently I have installed the mod_perl module into apache, and used the PerlModule ModPerl::Registry directive.

PerlModule ModPerl::Registry
PerlModule CGI
PerlSendHeader On

Alias /perl/ /real/path/to/perl/scripts/
<Location /perl>
SetHandler  perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
</Location>

<Files *.perl>
SetHandler  perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
</Files>

I've read that using this I do not need to modify my cgi perl code. (I always use strict pragma, so don't worry about uninitialized global variables and stuff like that).

My original script still works as intended, except for one thing, files that I included with the require() function can no longer be resolved.

script.cgi:

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard Vars);
require "includes/functions.cgi";

#blah blah, more stuff

script.perl

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard Vars);
require "includes/functions.perl"; # <---- Returns error:  Can't locate includes/functions.perl in @INC
#blah blah, more stuff

The directory structure works like this:

$ ls

script.cgi script.perl includes/

$ ls includes/

functions.cgi functions.perl

From: http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html

META: document that for now we don't chdir() into the script's dir, because it affects the whole process under threads. ModPerl::RegistryPrefork should be used by those who run only under prefork MPM.

so, if you're using Apache2's prefork MPM, you should try using ModPerl::RegistryPrefork. If you're using worker, or event, or windows, you're going to have to change your program to not assume that the cwd is the directory that that the perl is sitting in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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