http://www.perlmonks.org?node_id=609060

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

Most revered monks,
I have the following simple Perl script (called "hellom.cgi"):
__BEGIN__ #!/usr/bin/perl use CGI qw/:standard :html3/; use CGI::Carp qw( fatalsToBrowser ); $CGI::POST_MAX=1024 * 100; # max 100K posts1 #-------------------------------------------------- # BEGIN { # if ( $ENV{PERL5LIB} and $ENV{PERL5LIB} =~ /^(.*)$/ ) { # # # Blindly untaint. Taintchecking is to protect # # from Web data; # # the environment is under our control. # eval "use lib '$_';" foreach ( # reverse # split( /:/, $1 ) # ); # } # } #-------------------------------------------------- use Acme::Spork; use Bio::Tools::GuessSeqFormat; print "Content-type: text/html\n\n"; print "Hello World !! It works.\n"; __END__
Which is stored under: /usr/local/apache/htdocs/Test/cgi-bin And the actual website can be accessed here. It gives error message like this:
Software error: Can't locate Acme/Spork.pm in @INC (@INC contains: /home/sadm/lib/site +_perl/ /home/sadm/lib/site_perl/sun4-solaris-64int /usr/perl5/5.8.4/l +ib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4 +/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl / +usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl +/5.8.4 /usr/perl5/vendor_perl .) at /usr/local/apache/htdocs/Test/cgi +-bin/hellom.cgi line 25. BEGIN failed--compilation aborted at /usr/local/apache/htdocs/Test/cgi +-bin/hellom.cgi line 25. For help, please send mail to the webmaster (admin@your-domain.com), g +iving this error message and the time and date of the error.
As you can see from that link it shows that it can't locate Acme::Spork at the shown path there - although the path stated above (the one under /home) is already consistent with my htaccess path below:
SetEnv PERL5LIB /home/sadm/lib/site_perl/sun4-solaris-64int:/home/sadm +/lib/site_perl/
The .htaccess is located here: /usr/local/apache/htdocs/Test.
Moreover checking the location of the module it consistently shows the correct path:
sadm@bioinfo-z:~/lib/site_perl/Acme$ ls Spork.pm sadm@bioinfo-z:~/lib/site_perl/Acme$ pwd /home/sadm/lib/site_perl/Acme
My question is why my Apache can't locate the location given my correct .htaccess path? Thus my script won't work?

Update: Problem solved. Thanks to ikegami!.

Regards,
Edward
PS: My httpd.conf is this and modules.conf is this.

Replies are listed 'Best First'.
Re: Accessing Perl Modules Through .htaccess
by ikegami (Patriarch) on Apr 10, 2007 at 03:04 UTC
    Does the web server (specifically, the user "deamon" and the group "deamon") have access to the file and to the directories needed to access the file?
      How can we check that, ikegami?
      Do you mean the permission for the module? For the module I have the following permission:
      sadm@bioinfo-z:~/lib/site_perl/Acme$ ll -h total 7.0K -r--r--r-- 1 sadm sadmg 6.3K Jan 18 02:53 Spork.pm
      And doing chmod a+x on it, still Apache can't locate the module.

      Regards,
      Edward

        You only answered half the question.
        What about the permissions for /home/sadm/lib/site_perl/Acme?
        What about the permissions for /home/sadm/lib/site_perl?
        What about the permissions for /home/sadm/lib?
        What about the permissions for /home/sadm?
        What about the permissions for /home?

Re: Accessing Perl Modules Through .htaccess
by naikonta (Curate) on Apr 10, 2007 at 03:48 UTC
    The user/group running the Apache, in your case as httpd.conf configured, daemon, must have a read access to the Pork.pm. It means that not only Pork.pm must have permission of 'r' for daemon, but also all parts in the path hieararchy enable daemon to "walktrough" to eventually read Pork.pm. This means at least the 'x' bit must be turned on for daemon.

    Out of all.... You don't really need all that noise lines you now comment on. If you use PERL5LIB, perl automatically includes that in @INC. There's no point to untaint PERL5LIB either, because it will be ignored by perl in -T (taint mode), anyway. If you don't trust yourself, why didn't you put -T explicitly and see how's it going? And "use strict;", and "use warnings;".

    However, if you insist to parse a lib path, assumming you really trust the source, this simple snip will do:

    BEGIN { # $custom_path: you may obtain this global somewhere # outside of your code. You really need to reverse? unshift @INC, reverse split /:/, $custom_path; }
    eval "use something;" just never works.