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.
source share