Tuesday, August 9, 2011

install perl DBD::Oracle (Lesson learned: CPAN and yum don't mix)

From the many tales of woe on the web about installing perl DBD::Oracle, from "invalid lvalue in assignment" to mysterious make errors, and the pages of intricate instructions doubtfully translated from the French, I assumed that it was a long and difficult process and it was natural that I was having problems installing on 64-bit CentOS. WRONG! It can actually be easy for lazy and dumb people like me.

First, just use yum and hand-compiling. Don't add CPAN to the mix.
  1. Add the rpmforge repo and the EPEL repo (see links for instructions) so that you can install perl-DBD and perl-DBI via yum.
  2. Install perl-DBD and perl-DBI via yum.
  3. Download and install the OCI client "basic" and "sdk/devel" packages from Oracle. Note that you might need an older version if you're connecting to an older version of Oracle. Note also that Oracle makes you log in to download this. Note also that you need both the SDK and the Basic package. I recommend getting the rpms - install with a simple rpm -Uvh .
  4. Oracle puts the libraries in a wacky place, e.g. /usr/lib/oracle/11.2/client64/lib if you're using the 64-bit version of 11.2. Therefore, create a new file, e.g. oci.conf, in /etc/ld.so.conf.d/, with the library location in it, and then run (as root) ldconfig -v to add it.
  5. Download the DBD::Oracle source from cpan and extract it someplace. 
  6. Set some environment variables:
    export ORACLE_HOME=/usr/lib/oracle/11.2/client64
    export PATH=$PATH:$ORACLE_HOME/bin
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
  7. Run "perl Makefile.PL -V 11.2.0" in the directory where the OCI client was extracted. Change the version number to whatever the correct version is. This avoids the "I could not determine Oracle client version so I'll just default to version 8.0.0.0" issue.
  8. Run "make install".
  9. You should be done!

The latest versions of the Oracle Instant Client default to making incredibly verbose logs in the user's home directories - how to disable default oradiag_user instant client logging.

7 comments:

  1. hello,
    i can't install perl-DBD via yum
    i installed rpmforge and EPEL repo but still can't install perl-DBD with yum

    ReplyDelete
  2. hi,

    thanks for your instructions. I have two remarks. You don't need to install perl-DBD. As far as I know there is no general perl-dbd, but many perl-dbd modules for different databases. What you are doing here is compiling the perl-dbd-oracle module yourself, so it makes no sense to install it.
    In 7. you have to run the "perl Makefile.PL -V 11.2.0" command in the directory where you extracted the DBD:Oracle sources not in the directory where you extracted the OCI client.

    Worked like a charm! Thanks!

    ReplyDelete
  3. incorporating xamdam's comments into above instructions:

    0. Assumption: Running linux x86_64. Downloading oracle client version 11.2.0.1 and perl DBD-Oracle-1.74.
    1. Log in as root and do the following...
    2. Install perl-DBI via yum.
    yum install perl-DBI
    3. Download rpms into /root/Downloads:
    oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm
    oracle-instantclient11.2-devel-11.2.0.1.0-1.x86_64.rpm
    4. Go into /root/Downloads directory.
    cd /root/Downloads
    5. Install rpms:
    rpm -i oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm
    rpm -i oracle-instantclient11.2-devel-11.2.0.1.0-1.x86_64.rpm
    6. Go into directory /etc/ld.so.conf.d
    cd /etc/ld.so.conf.d
    7. Create new file "oci.conf" and add the following path to this file, then save & exit.
    /usr/lib/oracle/11.2/client64/lib
    7. Run the following command:
    ldconfig -v
    8. Set environment variables at the command line:
    export ORACLE_HOME=/usr/lib/oracle/11.2/client64
    export PATH=$PATH:$ORACLE_HOME/bin
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    9. Go into /root/Downloads directory.
    cd /root/Downloads
    10. Open browser and go to URL: http://search.cpan.org/
    11. Search for the following: DBD::Oracle
    12. Click on link "DBD::Oracle"
    13. On right hand side under "Download", click on the DBD-Oracle-x.xx.tar.gz
    Below is the URL that I downloaded at the time of this writing:
    http://search.cpan.org/~pythian/DBD-Oracle-1.74/lib/DBD/Oracle.pm
    Compressed archived file looks like this after downloaded: DBD-Oracle-x.xx.tar.gz
    14. Extract DBD-Oracle-x.xx.tar.gz located in /root/Downloads directory.
    tar zxvf DBD-Oracle-x.xx.tar.gz
    15. Extracted directory location: /root/Downloads/DBD-Oracle-x.xx
    16. Go into directory /root/Downloads/DBD-Oracle-x.xx
    cd /root/Downloads/DBD-Oracle-x.xx
    17. Run the following command:
    perl Makefile.PL -V 11.2.0.1
    18. Run the following command:
    make install
    19. Done.

    ReplyDelete
    Replies
    1. Thanks for making the internet a better place, Matthew.

      Delete
  4. Replies
    1. Ha, I am so sorry that you're having to struggle with this in 2017. That's actually horrific.

      Delete
  5. Hi to all!
    I am my OS Oracle Linux two users: root and oracle
    1) under what user need install cpan modules?
    2) if necessary install oracle CLIENT if installed ORACLE Enterprise Edition?

    MY PROBLEM:
    my perl script sucessfully work on comand line (connect to DB and give result from table)
    perl test.pl, but not work in browser(apache server)

    ORACLE_HOME=/u01/app/oracle/product/12.1/dbhome_1
    But perl not search *.so files /usr/lib64/......|
    (this *.so filel locate in $ORACLE_HOME/lib)

    3) What need right variable:
    ORACLE_HOME, PERL5LIB, LD_LIBRARY_PATH, PATH?????

    After copy needs *.so from oracle_home/lib to /usr/lib64 i am give error in apache log:
    error ocienvnlsCREATE, check oracle home......
    This manual not help me((((

    ReplyDelete

Note: Only a member of this blog may post a comment.