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

I recently took a VPS with a hosting company to run a CGI/Perl based website. I needed Image::Magick and asked them to install it for me. They installed it in
/usr/lib/perl5/vendor_perl/
This directory is not in @INC and my scripts fail with a module not found error. How can I add the path to @INC so that the CGI scripts (run as nobody) work?

Replies are listed 'Best First'.
Re: Perl library include path
by choroba (Cardinal) on Jun 12, 2014 at 13:25 UTC
    Doesn't the path continue with the version number?

    You can add the path to your scripts:

    use lib '/usr/lib/perl5/vendor_perl/5.10';

    Setting the $PERL5LIB environment variable is another option, but I'm not sure it's available for nobody. It might be configurable via the web server, e.g. in Apache, you'd add something like the following to the .htacces:

    SetEnv PERL5LIB /usr/lib/perl5/vendor_perl/5.10
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thanks for the response.

      What you have suggested would mean that I would have to add the 'use' part to a fair number of scripts (which I may do if I have no other option).

      I am looking into the Apache option if that is something I can do.

        You should fix the underlying problem. See my other posts above.
Re: Perl library include path
by perlfan (Parson) on Jun 12, 2014 at 14:52 UTC
    One thing that this tells me is that the `perl` being used in your CGI environment is not the one for which your I::M module was installed. Fwiw, when Image::Magick is typically installed when the ImageMagick bin utils are installed (e.g., `convert`). It is possible that the Perl module was installed in a non-standard location, but typically it goes into the default @INC location for the system `perl`. You may want to confirm with your provider that they installed it properly - or at least for the same `perl` you're using in your CGI scripts.

    If you're using a VPS, does this mean you have root access to the "box"? If so you can add PERL5LIB envar to your Apache httpd.conf file. Even if not, you should be able to request the ability to maintain your own .htaccess file. This would allow you to set an appropriate environmental variable with the proper Perl path to I::M.

      I see what you are saying. I will try to see if I can get my hosting provider address the issue. Yes, I do have root access, so I can try the other option as well.
        You don't need root access. In any of the scripts: use lib '/path/to/module/';
Re: Perl library include path
by LanX (Saint) on Jun 12, 2014 at 13:26 UTC
      When googling, it seemed to me that the only option that was available to me was to have Perl recompiled.
        You're looking at this backwards. I::M should have been installed wrt to either system `perl` or the `perl` your CGI environment is using. It gets installed as part of the ImageMagick library and set of tools, it is not typically installed as a standalone Perl module. If not, the provider did it wrong or you're using the wrong `perl` your CGI script shebang.