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

Hello my monkitudinous friends,

Yes, I've searched for the answer for this already, but it's not the same question I've seen over and over again...

I've a cgi script that is trying to load a custom module. I have the module in a folder in my user directory where it is being developed.I've added this directory to @INC with the "use lib..." statement.

So why does it say it can't find the module? I know it's there. The cgi script runs under user www, but the permisions of the module and containing folder are 777...

What do I do?

Thanks very much in advance!

Replies are listed 'Best First'.
Re: cgi script can't load my module
by almut (Canon) on Jul 29, 2007 at 20:24 UTC
    the permisions of the module and containing folder are 777

    All parent directories up in the hierarchy also need to be accessible by the webserver, i.e. at least their 'x' bit must be set. Have you checked that? (this is often overlooked)

    (BTW, don't get into the habit of setting files/directories world writeable without a good reason — it could bite you some time...)

Re: cgi script can't load my module
by jZed (Prior) on Jul 29, 2007 at 20:08 UTC
    The webserver may not be serving the CGI from the same directory structure as you are using from the command line. Are you using a relative path to the module? If so, you may need to use Cwd to find out where the webserver thinks your script is running from.
      Nope. I've given it the absolute path. And I've verified that it's looking there by printing @INC in the scripts output.

      Could it be some weird permissions thing? Something to do with my apache config not allowing external perl modules if the module is someplace it doesn't like? ???

Re: cgi script can't load my module
by Cody Pendant (Prior) on Jul 29, 2007 at 20:26 UTC
    Well, does it work from the command line?

    And how about you give us some actual code? And some paths? It could be a typo for all we know at the moment.



    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
      OK... I moved the folder containing the modules to a standard location, (/Library/Perl . I'm on OSX). It works fine in that folder. It's just inconvenient to develop in one folder and move stuff there.

      I changed the permissions all the way up the tree of my user directory as a test, but it didn't help...

      I'm absolutely sure there are no typos in the path. I've done the use lib thing before many times, just not with cgi. I'm new at the perl cgi part.

      I really think it might have something to do with my apache server setup.

      But anyway, I guess I'm just going to move it there for now, because I'm in a hurry to get some work done.

      Thanks for the tips. I'll check back later in case anyone has any other thoughts.

        I changed the permissions all the way up the tree of my user directory as a test, but it didn't help...  I'm absolutely sure there are no typos in the path.

        In that case it could be restricted access due to some SELinux or AppArmor configuration (the latter is likely if the box is running a newer SUSE Linux).  It's hard to tell, though, as you haven't told us anything about the platform this is...  (Update: Sorry, I overlooked the OSX in your reply...)

        I had a thought! I had two thoughts. They are:
        • tell us if it works from the command line
        • tell us what the code and the paths actually are

        Oh and as for:

        It's just inconvenient to develop in one folder and move stuff there.
        So ... just don't do that then.


        Nobody says perl looks like line-noise any more
        kids today don't know what line-noise IS ...
Re: cgi script can't load my module
by shmem (Chancellor) on Jul 30, 2007 at 04:53 UTC
    So why does it say it can't find the module? I know it's there. The cgi script runs under user www, but the permisions of the module and containing folder are 777...

    What do I do?

    First, you post the exact error message here (inside <code> tags, mind you). Then we'll see.

    I'd write a small CGI script which tries to open the module file in question (dying $!). If it barfs, I'd try to chdir where the module file lives, splitting the path and going down each folder. That would give clues.

    --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}
Re: cgi script can't load my module
by superfrink (Curate) on Jul 30, 2007 at 06:51 UTC
    So why does it say it can't find the module? I know it's there. The cgi script runs under user www, but the permisions of the module and containing folder are 777.

    Double check everything you think you know to be true. I saw a site change hosting companies. Part of the site was mod_php and part was Perl CGI. The new company had mod_php ran as the apache user and the CGI ran as the hosting customer's user. The CGI could not read the PHP session files so the site broke.

    Write a CGI that prints out the uid, euid, gid, and egid. (See perlvar).

    Like shmem mentioned try to open the file and print the value of $!. Run ls -dl on each hard-coded directory in the file's absolute path.

    Print the value of @INC. Use something like (untested):
    #!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use Data::Dumper; my $file = "/data/www/mods/foo.pm"; print $< , "\n"; print $> , "\n"; print $( , "\n"; print $) , "\n"; print Dumper(\@INC); system('/bin/ls -dl /data'); system('/bin/ls -dl /data/www'); system('/bin/ls -dl /data/www/mods'); system('/bin/ls -dl /data/www/mods/foo.pm'); open FH, "<" . $file or die $!;