Skip to content

Building a local environment for an application

0defect edited this page Mar 6, 2012 · 1 revision

Building a local environment for an application

If you want to build a local environment for an application, do the following (This works in Linux):

Create the user account for the application

First, create the user the application will run under. This must be done as root.

useradd app1

and set the password for the user.

passwd app1

change to the user app1

su - app1

Install cpanm

cpanm is a CPAN module management tool. It is handy to have, so let's install it. You can install the CPANM module easily into your home directory:

curl -L http://xrl.us/cpanm > cpanm
perl cpanm App::cpanminus

This installs the cpanm installation script in your current directory, and then runs it. If you install CPAN module by cpanm, the module is installed under the ~/perl5 directory.

Set up the environment

Assuming you are using bash, write the following in your .bashrc file

export PERL_CPANM_OPT="--local-lib=~/perl5"
export PATH=$HOME/perl5/bin:$PATH;
export PERL5LIB=$HOME/perl5/lib/perl5:$PERL5LIB;

PERL_CPANM_OPT tells cpanm where to find modules. The PATH variable helps the shell find commands installed by cpanm, or cpanm itself. PERL5LIB will do the same for Perl.

Th next time you log in, those variables will take effect. If you do not want to wait, type the following:

source ~/.bashrc

Module installation

Try to install Data::Page:

cpanm Data::Page

You can see Data::Page in "~/perl5/lib/perl5" with ls:

ls ~/perl5/lib/perl5

You can test that everything is ok by using a quick one-liner:

perl -MData::Page -e 1

or:

perl -e 'use Data::Page'

If you don't see an error message, the installation is a success.

Mirror, if needed the application environment to a different server

It is easy to transfer settings to a new server, if the architecture is the same. You only need to copy the following to the same location (for the same user account):

1. The ~/perl5 directory.
2. Your application.
3. Your .bashrc additions.
Clone this wiki locally