dsharvit has asked for the wisdom of the Perl Monks concerning the following question:

Hi, can relative paths be used in cgi's that are loaded using mod_perl, if not then how do I configure apache to recognize the environment in which the perl cgi lives? Thanks Dana

Replies are listed 'Best First'.
Re: cgi environment using mod_perl
by Coruscate (Sexton) on Jan 21, 2004 at 10:25 UTC

    When under a mod_perl environment, the directory that the perl script is started in can differ from the directory in which the script file itself is located. I'm not sure if it is always the case, but my mod_perl starts scripts up from the apache root (So in my case C:/Apache2/www/port80/serve/foo.pl is executed as though it were C:/Apache2/foo.pl). The simplest way to make it back to regular CGI behaviour is to change directory from within perl. So at the top of your script, you just throw in this line:

    BEGIN { chdir "/path/to/script/directory" }

    My foo.pl script as mentioned above for example, would include this line:

    BEGIN { chdir "C:/Apache2/www/port80/serve" }

      That's only the case with mod_perl 2. In mod_perl 1, Apache::Registry does the chdir automatically.

        I'll remember that in case I ever have to suffer the long journey of porting anything from mod_perl 1.x to mod_perl 1.9x/2.x. That would certainly be a strange thing to see happen if you're not expecting it. :)