How To Install Perl Modules
On Shared Hosting
(For other situations, see the Perl Modules main page.)
If you need a Perl module installed on your server, the best thing to do is to simply ask your hosting company to install it. However, some hosting companies are unwilling to install Perl modules for their clients. Fortunately there's a relatively simple workaround that works in many cases.
You can "install" the Perl module yourself, within your own web space, just for your own CGI scripts. To the scripts, this is exactly the same as if the module were installed server-wide.
Step 1a: install the module the easy way
All you need to do is get the module from CPAN, unzip it and find the *.pm file within it, and then put that *.pm file into your cgi-bin directory.
Step 1b: install the module the hard way
Unfortunaltely, for more complex Perl modules, there won't be a *.pm file within the file that you download from CPAN. These kinds of modules need to be built manually on the system where they're going to be used. Building them is still usually pretty easy, but it's a little more work. You need to take the zip file from CPAN, unzip it, and put its contents onto your server, for example in a folder named ~/perltemp. Then SSH into the server, cd into the ~/perltemp/modulename folder, and then run these commands:
perl Makefile.PL PREFIX=./myoutput LIB=./myoutput
make
make install
When that's finished, you'll find a new subfolder within the myoutput folder, named something like "x86_64-linux-gnu-thread-multi". You need to go into that folder and copy all its contents (except for perllocal.pod which you can skip) into your website's cgi-bin folder.
Step 2: tell your script where to find the module
In your script, near the top, put the following 2 lines:
use lib "$ENV{DOCUMENT_ROOT}/cgi-bin";
The first line tells the script to look in the current directory for Perl modules; the second line explicitly specifies the cgi-bin directory. One or both of those lines should work on most servers, and it doesn't hurt to add them both.
For Encodable apps like FileChucker and UserBase, they're pre-programmed to look for Perl modules in a directory called cgi-bin/perlmodules/ so you don't need to edit the script at all; just create a directory called perlmodules within your cgi-bin directory and put your modules into it.
As a final note, many Perl modules are named in 2 parts; for example, there's a module called "File::Mirror" which can be used to copy whole directories recursively. To install this module within your perlmodules directory, you first create a subdirectory called "File", and then you put the "Mirror.pm" file into the "File" folder. Then the module will be at cgi-bin/perlmodules/File/Mirror.pm.