Installing mod_perl without superuser privileges
by Stas BekmanApril 10, 2002
In the examples, I'll use stas as a username, and /home/stas as the home directory for that user.
Installing Perl Modules Into a Directory of Choice
Since without superuser permissions you aren't allowed to install modules into system directories such as /usr/lib/perl5, you need to find out how to install the modules under your home directory. It's easy.
First, you have to decide where to install the modules. The simplest approach is to simulate the portion of the / file system relevant to Perl under your home directory. Actually we need only two directories:
/home/stas/bin
/home/stas/lib
We don't have to create them, since that will be done automatically when the first module is installed. Ninety-nine percent of the files will go into the lib directory. Occasionally, when some module distribution comes with Perl scripts, these will go into the bin directory. This directory will be created if it doesn't exist.
Let's install the CGI.pm package, which includes a few other
CGI::* modules. As usual, download the package from the CPAN
repository, unpack it and chdir to the newly created directory.
Now do a standard perl Makefile.PL to prepare a Makefile, but
this time tell MakeMaker to use your Perl installation directories
instead of the defaults.
% perl Makefile.PL PREFIX=/home/stas
PREFIX=/home/stas is the only part of the installation process
that is different from usual. Note that if you don't like how
MakeMaker chooses the rest of the directories, or if you are using
an older version that requires an explicit declaration of all
the target directories, then do this:
% perl Makefile.PL PREFIX=/home/stas \
INSTALLPRIVLIB=/home/stas/lib/perl5 \
INSTALLSCRIPT=/home/stas/bin \
INSTALLSITELIB=/home/stas/lib/perl5/site_perl \
INSTALLBIN=/home/stas/bin \
INSTALLMAN1DIR=/home/stas/lib/perl5/man \
INSTALLMAN3DIR=/home/stas/lib/perl5/man3
The rest is as usual:
% make
% make test
% make install
make install installs all the files in the private repository.
Note that all the missing directories are created automatically, so
there is no need to create them. Here (slightly
edited) is what it does :
Installing /home/stas/lib/perl5/CGI/Cookie.pm
Installing /home/stas/lib/perl5/CGI.pm
Installing /home/stas/lib/perl5/man3/CGI.3
Installing /home/stas/lib/perl5/man3/CGI::Cookie.3
Writing /home/stas/lib/perl5/auto/CGI/.packlist
Appending installation info to /home/stas/lib/perl5/perllocal.pod
If you have to use the explicit target parameters, then instead of a single
PREFIX parameter, you will find it useful to create a file called,
for example, ~/.perl_dirs (where ~ is /home/stas in our
example) containing:
PREFIX=/home/stas \
INSTALLPRIVLIB=/home/stas/lib/perl5 \
INSTALLSCRIPT=/home/stas/bin \
INSTALLSITELIB=/home/stas/lib/perl5/site_perl \
INSTALLBIN=/home/stas/bin \
INSTALLMAN1DIR=/home/stas/lib/perl5/man \
INSTALLMAN3DIR=/home/stas/lib/perl5/man3
From now on, any time you want to install Perl modules locally, you simply execute:
% perl Makefile.PL `cat ~/.perl_dirs`
% make
% make test
% make install
Using this method, you can easily maintain several Perl module repositories. For example, you could have one for production Perl and another for development:
% perl Makefile.PL `cat ~/.perl_dirs.production`
or
% perl Makefile.PL `cat ~/.perl_dirs.develop`
Making Your Scripts Find the Locally Installed Modules
Perl modules are generally placed in four main directories. To find these directories, execute:
% perl -V
The output contains important information about your Perl installation. At the end you will see:
Characteristics of this binary (from libperl):
Built under linux
Compiled at Apr 6 1999 23:34:07
@INC:
/usr/lib/perl5/5.00503/i386-linux
/usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005
.
It shows us the content of the Perl special variable @INC, which is
used by Perl to look for its modules. It is equivalent to the PATH
environment variable in Unix shells that is used to find executable
programs.
Notice that Perl looks for modules in the . directory too, which stands for the current directory. It's the last entry in the above output.
Of course, this example is from version 5.00503 of Perl installed on my x86 architecture PC running Linux. That's why you see i386-linux and 5.00503. If your system runs a different version of Perl, operating system, processor or chipset architecture, then some of the directories will have different names.
I also have a perl-5.6.1 installed under /usr/local/lib/ so when
I do:
% /usr/local/bin/perl5.6.1 -V
I see:
@INC:
/usr/local/lib/perl5/5.6.1/i586-linux
/usr/local/lib/perl5/5.6.1
/usr/local/lib/site_perl/5.6.1/i586-linux
/usr/local/lib/site_perl
|
Previously in the Series |
Note that it's still Linux, but the newer Perl version uses the version of my Pentium processor (thus the i586 and not i386). This makes use of compiler optimizations for Pentium processors when the binary Perl extensions are created.
All the platform specific files, such as compiled C files glued to
Perl with XS or SWIG, are supposed to go into the
i386-linux-like directories.
Important: As we have installed the Perl modules into nonstandard
directories, we have to let Perl know where to look for the four
directories. There are two ways to accomplish this: You can
set the PERL5LIB environment variable or you can modify the
@INC variable in your scripts.
Assuming that we use perl-5.00503, in our example the directories are:
/home/sbekman/lib/perl5/5.00503/i386-linux
/home/sbekman/lib/perl5/5.00503
/home/sbekman/lib/perl5/site_perl/5.005/i386-linux
/home/sbekman/lib/perl5/site_perl/5.005
As mentioned before, you find the exact directories by executing
perl -V and replacing the global Perl installation's base
directory with your home directory.
Modifying @INC is quite easy. The best approach is to use the
lib module (pragma), by adding the following snippet at the top of
any of your scripts that require the locally installed modules.
use lib qw(/home/stas/lib/perl5/5.00503/
/home/stas/lib/perl5/site_perl/5.005);
Another way is to write code to modify @INC explicitly:
BEGIN {
unshift @INC,
qw(/home/stas/lib/perl5/5.00503
/home/stas/lib/perl5/5.00503/i386-linux
/home/stas/lib/perl5/site_perl/5.005
/home/stas/lib/perl5/site_perl/5.005/i386-linux);
}
Note that with the lib module we don't have to list the
corresponding architecture specific directories, since it adds them
automatically if they exist (to be exact, when $dir/$archname/auto
exists).
Also, notice that both approaches prepend the directories to be
searched to @INC. This allows you to install a more recent module
into your local repository and Perl will use it instead of the older
one installed in the main system repository.
Both approaches modify the value of @INC at compilation time. The
lib module uses the BEGIN block as well, but internally.


