Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

module not found errors in a mod_perl handler

by tomgracey (Scribe)
on Dec 15, 2022 at 18:07 UTC ( [id://11148896]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks

I am messing around creating some kind of basic proxy system using a mod_perl handler. I have some code like this:

package My::Handler; use strict; use warnings; use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK); use LWP::UserAgent (); sub handler{ my ($r) = @_; my $ua = LWP::UserAgent->new; my $resp = $ua->get( $r->unparsed_uri ); $r->print( $resp->decoded_content ); return Apache2::Const::OK; }

and in my apache config:

<Perl> use lib "/my/handler/lib"; </Perl> PerlModule My::Handler <Location /> Require all granted SetHandler perl-script PerlResponseHandler My::Handler </Location>

However, when I run it I seem to get

Can't locate HTTP/Config.pm: /my/handler/lib/HTTP/Config.pm: Permiss +ion denied at /<perlbrew path>/perl-5.34.0/lib/site_perl/5.34.0/LWP/U +serAgent.pm line 865.

If I add use HTTP::Config under use LWP::UserAgent at the top, it then complains about another missing module. It seems to be expecting to find these modules in /my/handler/lib, even though when I dump @INC this appears to contain all the perlbrew paths to the perl version (v34.0) I am using as expected. I tried copying verbatim a handler from the mod perl docs but with the same result. I am guessing therefore the problem is something to do with my setup and/or apache setup - but what? Any thoughts/suggestions would be helpful. Thanks!

Replies are listed 'Best First'.
Re: module not found errors in a mod_perl handler
by hippo (Bishop) on Dec 15, 2022 at 18:58 UTC

    The error message suggests that the user mod_perl is running under does not have permissions to read /my/handler/lib/HTTP/Config.pm so if you go up the tree from there until you find the offending directory and allow read perms for the mod_perl user that might be all that is needed. Worth a try, anyway.

    Are you on a system using SELinux or AppArmor? That might also be a consideration.


    🦛

      Thanks for your suggestion. Sorry to be clear, HTTP::Config is not located in the /my/handler/lib directory - this only has my custom hander in it. HTTP::Config (and other installable perl modules) are located in the perlbrew install directories. I have checked permissions on these dirs, and they are r and x for all users.

      In this case I'm on Centos7.9 with no SELinux/AppArmor.

        Sorry to be clear, HTTP::Config is not located in the /my/handler/lib directory

        Yes, I understood that and it doesn't matter whether the module is there or not. You have set it up so that the process looks there first and if it doesn't have the rights to do so, that results in the fatal error message you have seen. Here's a trivial demo of this principle:

        $ perl -I/root/bin -e 'use CGI' Can't locate CGI.pm: /root/bin/CGI.pm: Permission denied at -e line +1. BEGIN failed--compilation aborted at -e line 1. $ perl -e 'use CGI' $

        The first attempt fails because my (non-root) user has no access to the first path in @INC. The second one succeeds.


        🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11148896]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found