Standalone Perl with DBI, Oracle Instant Client, and DBD::Oracle in 10 minutes
In some cases, you may not have elevated access on a linux box to install/configure perl modules. You can install all of this under a home directory of any user in linux without having root access or conflicting with the system-wide perl installation. In order to have a standalone environment where Perl can connect to an Oracle database, you need the following:
- Perl
- Perl DBI Module
- Oracle Drivers
- Perl DBD::Oracle Module
Here is what I did in order to create a standalone installation of perl that includes all of this. After reading through many different websites, I could not find one that had everything laid out like this, so I decided to piece together all the bits and pieces that I gathered from a handful of websites. This was done on a CentOS 5.3 box (the equivalent of Redhat Enterprise 5.3). After writing this, I went back under a different user id and ran through the entire installation process again, including running the test perl script and completed it all in under 10 minutes. Thanks to one reader who pointed out that if you are a box where the tar command doesn’t accept the “z” flag (i.e. a sun box), you’ll have to gunzip first, then tar -xvf on any of the .tar.gz files mentioned.
**At the time of this writing (11/11/2010), the latest versions were:
- Perl – 5.12.2
- DBI – 1.615
- Oracle Instant Client – 11g (11.2.0.2.0)
- DBD::Oracle – 1.26
Step 1: Install Perl into a directory that is separate from the system-wide perl install:
This will install it to localperl under your home directory.
$ cd $ wget http://www.cpan.org/src/5.0/perl-5.12.2.tar.gz $ tar -zxvf perl-5.12.2.tar.gz $ cd perl-5.12.2 $ ./Configure -des -Dprefix=$HOME/localperl $ make test (optional) $ make install
Now you have a separate version of perl installed in ~/localperl. To verify that you have a different version installed, first check the system-wide perl:
$ which perl /usr/bin/perl $ perl -v This is perl, v5.8.8 built for i386-linux-thread-multi Copyright 1987-2006, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Locally installed perl in ~/localperl:
$ $HOME/localperl/bin/perl -v This is perl 5, version 12, subversion 2 (v5.12.2) built for i686-linux Copyright 1987-2010, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.
In my case the most recent version of perl is newer than what shipped with CentOS 5.3, so verification is easy. You can see that the one installed in $HOME/localperl is the newer than the system-wide perl in /usr/bin (5.12.2 vs 5.8.8).
Step 2: Install the Perl DBI Module
Make a temporary directory for the perl module builds:
$ cd $ mkdir $HOME/perlbuilds $ cd $HOME/perlbuilds $ wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.615.tar.gz $ tar -zxvf DBI-1.615.tar.gz $ cd DBI-1.615 $ $HOME/localperl/bin/perl Makefile.PL PREFIX=~/localperl $ make $ make test (optional) $ make install
**At the time of this, the latest Perl DBI version is 1.615. You can get the link to download the latest always from http://dbi.perl.org/ and clicking on “Download latest”.
Alternatively, you can use CPAN to install the Perl Modules. If you do, ensure that when setting up CPAN that you do not select auto-configure. For most of the setup options, you can just hit the Enter key for the default value. When asked about Parameters for the Makefile.PL and Build.PL commands, enter the following:
Would you like me to configure as much as possible automatically? [yes] no ... Parameters for the 'perl Makefile.PL' command? [ ] PREFIX=~/localperl Parameters for the 'perl Build.PL' command? [ ] --install_base ~/localperl
Once done setting up CPAN, you can install DBI module as follows:
cpan[1]> install DBI
To verify that DBI is working, run the following:
$ $HOME/localperl/bin/perl use DBI; $
After entering the “use DBI;” line, you should be brought to a blank line. Hit CTRL-D to return to a command prompt. If you return cleanly to a command prompt, then it successfully loaded the module. If not, you’ll see something like this:
$ perl use DBI; Can't locate DBI.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at - line 1. BEGIN failed--compilation aborted at - line 1.
Step 3: Install the Oracle Instant Client
If all you need is to be able to connect to an Oracle database that runs on a different server, who wants to go through the entire Oracle install just to get Perl to be able to connect? The DBD::Oracle Perl Module will compile just fine against the Oracle Instant Client. It is a very lightweight and easy install.
- Download the base instant client
- Download the sdk instant client
- Download the sqlplus instant client
- put all three zip files in the $HOME/localperl directory
- Set the following Environment Variables:
$ export ORACLE_HOME=$HOME/localperl/instantclient_11_2 $ export LD_LIBRARY_PATH=$ORACLE_HOME
**Ensure you get the zips for these and not the rpms
$ cd $HOME/localperl $ unzip instantclient-basic-linux32-11.2.0.2.0.zip $ unzip instantclient-sdk-linux32-11.2.0.2.0.zip $ unzip instantclient-sqlplus-linux32-11.2.0.2.0.zip
Step 4: Install the DBD::Oracle Perl Module
$ cd ~/perlbuilds $ wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBD-Oracle-1.26.tar.gz $ tar -zxvf DBD-Oracle-1.26.tar.gz $ cd DBD-Oracle-1.26 $ $HOME/localperl/bin/perl Makefile.PL PREFIX=~/localperl $ make $ make install
**At the time of this, the latest Perl DBI version is 1.615. You can get the link to download the latest always from http://dbi.perl.org/ and clicking on “Find Latest DBD Modules” and browsing to the DBD::Oracle page.
Alternatively, you can use CPAN to install the DBD::Oracle module:
Alternatively, you can use CPAN to install the DBD::Oracle module:
cpan[2]> install DBD::Oracle