in reply to Perl - open with Apache

How does Apache invoke the script? mod_perl? CGI? FastCGI? It may simply be a setting in the configuration of one of these within Apache. If you just have a script which only prints those diagnostics and then exits, doing literally nothing else, then you can confirm that the PWD is being set outside the script itself. I would warn() instead of print() for this (so it will appear in the error log) but YMMV:

#!/usr/bin/env perl use strict; use warnings; warn "Directory is " . `pwd`; warn "Contents are \n" . `ls -al`; exit;

If that confirms it you might also want to dump %ENV to see what else might be going on.

Replies are listed 'Best First'.
Re^2: Perl - open with Apache
by djneely (Initiate) on Feb 04, 2020 at 17:57 UTC
    Interesting. Using your code in another script in the same directory. I'm getting the following. Not sure where that gets me but results I did not expect.
    ==> /var/log/apache2/error.log <== Directory is /srv/site/scripts Contents are total 36 drwxr-xr-x 2 derek derek 4096 Feb 4 17:49 . drwxrwxr-x 10 derek derek 4096 Feb 4 17:04 .. -rw------- 1 derek derek 12288 Feb 4 17:49 .test3.pl.swp -rw-r--r-- 1 derek derek 7 Feb 4 17:09 config.txt -rw-r--r-- 1 derek derek 434 Feb 4 17:41 test.pl -rw-r--r-- 1 derek derek 394 Feb 4 17:41 test2.pl -rw-r--r-- 1 derek derek 118 Feb 4 17:49 test3.pl
    As far as Apache goes the config is just simply:
    <Files ~ "\.(pl|cgi)$"> SetHandler perl-script PerlResponseHandler ModPerl::PerlRun Options +ExecCGI PerlSendHeader On </Files>

    Quick update and curious as to the difference.

    The header of the file on the old server is: #!/usr/local/bin/perl

    The scripts that we've been testing with are: #!/usr/bin/perl

    And the one provided in your test script was: #!/usr/bin/env perl

    When we update the scripts in questions to use the #!/usr/bin/env perl they seem to work.

    Thanks for your help been a long time since I've done perl and coming back at this as a noob.