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

Tonigth i chnages the scheme of my perl webpage instead of having index.html redirect to cgi-bin\index.pl i set in httpd.conf DirectoryIndex index.html cgi-bin/index.pl but all links to other ple scripts inside my index.pl not workign any more cause thye y were relative. Then i changed them alla links to files an folders to absolute startinf with a leading / (d:\www which is my DocumentRoor) Now script can work but but statements like :
my @files = glob "/data/text/*.txt"; and my @tips; open FILE, "/data/text/tips.txt" or die $!; @tips = <FILE>; close FILE;
arent opening files or loading them into arrays. The paths though to files ae correct. I just dont see the error. Linking fro one cgi to another is handled by the web server but opening/writing is handled by the OS. ok. But is nt it strange but the same commands used to work without full hdd paths in the past, until yesterday which i deleted the index.html that was pointing to index.pl?
How come then the webserver was able to handle those I/O requests and executed the properly?
i had it like this: cleint request => index.html (d:\www) => index.pl (d:\www\cgi-bin) and it was working ok.
Things changes when i deleted the redirection filer and set DirectoryIndex index.html cgi-bin/index.pl To put it more simply
When i used to sue the index.html pointing to index.pl all paths i ahd were relative and all I/O functions like fillign an @array with files or opening files used to work with, could be opened and edited without me having to describe the full hdd locations.
How was that possbile?

Replies are listed 'Best First'.
Re: Absolute Path errors
by shmem (Chancellor) on Apr 10, 2007 at 12:46 UTC
    Genereating the root directory index with some script living in the cgi-bin dircetory will not work. Try the following index.pl:
    #!/usr/bin/perl -w use CGI qw(:standard); use Cwd; my $dir = getcwd; print header, start_html(); print "<h1>Directory: $dir</h1>"; print end_html();

    You will note that the perl script's current working directory is the cgi-bin directory, which is most likely not what you want.

    I just dont see the error.

    Enrich your scripts with debug print statements sent to STDERR, and they will show up in the error log. It's hard to tell from outside what your issues really are; a perl script should be able to read absolute paths, the only gotcha here might be a chroot environment, and of course permssion issues.

    It would be of help (to help) if you posted your apache config (stripped of comments to keep it short).

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Absolute Path errors
by blazar (Canon) on Apr 11, 2007 at 08:09 UTC

    Why don't you say that you posted the very same question in clpmisc? (link @ GG.) Why aren't you reporting what they told you there?

      I see. He's just wasting our time :-(

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Absolute Path errors
by Moron (Curate) on Apr 10, 2007 at 11:44 UTC
    It is normal for apache not to follow absolute paths. Instead of trying to use symbolic links, configure virtual hosts and aliases.

    -M

    Free your mind

      It is normal for apache not to follow absolute paths.

      No, it's the other way round. It's normal for apache to resolve only absolute paths and not to follow symlinks, unless you explicitly tell it to do so via

      Options +FollowSymLinks

      update: as pointed out by naikonta in Re^3: Absolute Path errors, the default is Options All so I correct the abvove statement to "It's normal for any sensibly configured apache" ;)

      Thanks, naikonta, another point to be wary of.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        Although you are correct about how to switch on "follow" for symlinks, your "other way round" presents a false dichotomy. Turning symlinks on or off has no logical symbiosis with the distinction between relative and absolute paths, but creates four logical combinations rather than two. I am trying to say that Apache converts absolute pathnames into relative ones rather than following them literally, irrespective of whether they resolve into a symlink and get redirected after that.

        -M

        Free your mind