How can I find out DOCUMENT_ROOT in startup.pl in mod_perl2?

I want to find out DOCUMENT_ROOT in startup.pl, but the best I can do is examine server_root:

use Apache2::ServerUtil (); $server_root = Apache2::ServerUtil::server_root(); 

which is completely useless. I can set the environment variable with

 SetPerlEnv DOCUMENT_ROOT /path/to/www 

but I don’t like the additional setting, if possible.

Is there any way to get DOCUMENT_ROOT in other ways?

+4
source share
1 answer

See Apache2 :: Directive . For example, in my development system:

 use Apache2::Directive (); my $tree = Apache2::Directive::conftree(); my $vhost = $tree->lookup(VirtualHost => 'unur.localdomain:8080'); File::Slurp::write_file "C:/bzzzt.txt", [ $vhost->{DocumentRoot}, "\n" ]; 

created a file C:/bzzzt.txt with the contents of "E:/srv/unur/deploy/htdocs" after it found that I need to specify my virtual hosts using

 <VirtualHost unur.localdomain:8080> ... </VirtualHost> <VirtualHost qtau.localdomain:8080> ... </VirtualHost> 

not <VirtualHost *:8080> . Otherwise, each <VirtualHost *:8080> section overwrites the previous one.

This is annoying. I would think that every VirtualHost entry would be used with ServerName .

As for if there is an easier way, I'm afraid not if you want to do this in startup.pl . However, I am not sure if this should be done in startup.pl . You can find out the document root when processing a request using Apache2 :: RequestUtil :: document_root .

If you use registry scripts and want to change to DOCUMENT_ROOT , then you should be able to add:

 chdir $ENV{DOCUMENT_ROOT} or die "Cannot chdir to '$ENV{DOCUMENT_ROOT}': $!"; 

in a script instead of having to deal with startup.pl and handlers, etc.

+3
source

Source: https://habr.com/ru/post/1301481/


All Articles