Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

apache2 passing PERL5LIB environment to cgi

by debinix (Initiate)
on Jun 14, 2010 at 19:37 UTC ( [id://844715]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to install the perl based twiki, :-) Locally it works fine. However the host provider (running CentOS, and perl 5.8.0) does not allow installing all required modules except in my ~ directory.

Now I managed to install the few missing modules in ~/lib/perl5. The problem is just that perl is not aware of my local repository of modules.

I have tried some fault finding home with Apache v2.2.4 (Ubunty 7.10) aka tried to have Apache to pass the environment to my cgi-bin scripts like so:

<Directory /var/www/twiki>
    SetEnv PERL5LIB /home/debinix/lib/perl5
    Options All
    AllowOverride All
    Order Deny,Allow
    Allow from 192.168.0.0/255.255.255.0
</Directory>
$ perl -V outputs:
  @INC:
    /etc/perl
    /usr/local/lib/perl/5.8.8
    /usr/local/share/perl/5.8.8
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.8
    /usr/share/perl/5.8
    /usr/local/lib/site_perl
 
mod_perl is not used on the server. I kind of got stuck here. The apache log: "Can't locate Unicode/String.pm in @INC ..."
  • Comment on apache2 passing PERL5LIB environment to cgi

Replies are listed 'Best First'.
Re: apache2 passing PERL5LIB environment to cgi
by AndyZaft (Hermit) on Jun 14, 2010 at 19:48 UTC
    You could try "use lib <path>" inside the perl file and see if that works?

      I have a little test script that use the module

      #!/usr/bin/perl -w
      
      use lib "$ENV{HOME}/lib/perl5";
      use Unicode::String qw(utf8 latin1 utf16be);
      

      If I have "export PERL5LIB=~/lib/perl5" it works, and with commented out it does not work.

        That makes no sense. They should be equivalent. Both of the following should work, or both should fail.
        PERL5LIB= perl -e'use lib "$ENV{HOME}/lib/perl5"; use Unicode::String +qw(utf8 latin1 utf16be);' PERL5LIB=$HOME/lib/perl5 perl -e'use Unicode::String qw(utf8 latin1 ut +f16be);'

        Could you confirm or refute?

        Hmm, never used perl with apache without mod_perl before. Does it start a new perl instance on every cgi call? So at least you get response from the script right? I mean as HTML in a browser. When you print @INC after your use lib line, do you see your $HOME/lib/perl5 in there? Was just wondering if ENV{$HOME} actually would have the right path or would show up something like /home/nobody/lib/perl5 or /lib/perl5?
Re: apache2 passing PERL5LIB environment to cgi
by mikelieman (Friar) on Jun 15, 2010 at 15:13 UTC
    Why TWiki and not the open-source fork foswiki ( http://foswiki.org )?
Re: apache2 passing PERL5LIB environment to cgi
by rowdog (Curate) on Jun 15, 2010 at 18:29 UTC

    SetEnv should work fine as long as your server has mod_env enabled. If not, there are other ways to set environment variables in Apache.

    In the unlikely case that $HOME actually exists, it will most likely be useless since it would probably refer to ~apache and not ~you. I suppose that mod_suexec might be able to make it your $HOME again, but that's a lot of work for little gain.

    You might have a problem with permissions. For Apache to be able to read your files, you have to grant permissions for others to read. Maybe it's as simple as chmod o+x perl5lib. You can check if Apache can read the dir with a simple cgi that includes something like

    #!/usr/bin/perl -T print "Content-type: text/plain\n\n"; print "PERL5LIB is $ENV{PERL5LIB}\n" -X $ENV{PERL5LIB} and print "Apache can read $ENV{PERL5LIB}\n";

    If all else fails, use lib should do the trick, so I'd bet on a permissions problem.

    Update: made script useable.
Re: apache2 passing PERL5LIB environment to cgi
by Anonymous Monk on Jun 15, 2010 at 20:21 UTC
    use lib ... would appear to be the correct approach here.

    Have you verified that the apache user had the rights to read your ~/lib directory?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found