6 Replies Latest reply: Jun 29, 2012 11:50 AM by 946703 RSS

    DBD::Oracle works via perl CLI but not thru Apache

    921271
      Hi -

      I'm beating my head against a wall.

      We're trying to transition from our old Solaris machines to newer, virtual Linux machines. We're running CentOS, x86-64.

      Oracle Instant Client v11.2
      Perl: ActivePerl 5.14.2 built for x86_64-linux-thread-multi
      Apache: Apache/2.2.19 (Unix)
      DBI: v1.617
      DBD::Oracle v1.30

      I downloaded and installed the Oracle Instant Client RPMs - basic, devel, and sqlplus for 64-bit Linux.
      I can connect to a database via SQL*Plus just fine.

      I can run the following Perl script from the command line just fine.
      #!/bin/env perl
      
      BEGIN {
         $ENV{'ORACLE_BASE'} = "/usr/lib/oracle";
         $ENV{'ORACLE_HOME'} = "$ENV{'ORACLE_BASE'}/11.2/client64";
         $ENV{'LD_LIBRARY_PATH'} = "$ENV{'ORACLE_HOME'}";
         $ENV{'TNS_ADMIN'} = $ENV{'ORACLE_HOME'}
      };
      
      use DBI;
      #use DBD::Oracle;
      use CGI;
      
      my $q = new CGI();
      print $q->header();
      print $q->start_html("Oracle Test");
      print "Hello World!";
      print $q->p(`which perl`);
      print $q->p("PATH: " . $ENV{'PATH'}) . "\n";
      print $q->p("ORACLE_BASE: " . $ENV{'ORACLE_BASE'}) . "\n";
      print $q->p("ORACLE_HOME: " . $ENV{'ORACLE_HOME'}) . "\n";
      print $q->p("LD_LIBRARY_PATH: " . $ENV{'LD_LIBRARY_PATH'}) . "\n";
      print $q->p("TNS_ADMIN: " . $ENV{'TNS_ADMIN'}) . "\n";
      
      print "\n";
      
      my $dbh = DBI->connect("dbi:Oracle:my-oracle-server.com:1521/mydatabase",
         "username", "password") || die $DBI::errstr;
         
      my $sql = "SELECT * FROM cs_empnums";
      my $ary_ref = $dbh->selectall_arrayref($sql);
      
      print $q->table({border=>1, cellpadding=>5, cellspacing=>0});
      
      foreach my $row (@{$ary_ref})  {
         print $q->TR($q->td($row)) . "\n";
      }
      
      print $q->end_table();
      
      print $q->end_html();
      However, when I run it from a browser thru Apache, I get the following output:

      Hello World!
      /var/www/apps/ActivePerl/bin/perl
      PATH: /var/www/apps/ActivePerl/bin:/usr/bin:/bin
      ORACLE_BASE: /usr/lib/oracle
      ORACLE_HOME: /usr/lib/oracle/11.2/client64
      LD_LIBRARY_PATH: /usr/lib/oracle/11.2/client64
      TNS_ADMIN: /usr/lib/oracle/11.2/client64

      and the following in my apache error log:
      [Thu Mar 01 18:51:47 2012] [error] [client 172.22.15.177] install_driver(Oracle) failed: Can't load '/var/www/apps/ActivePerl-5.14/lib/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object file: No such file or directory at /var/www/apps/ActivePerl-5.14/lib/DynaLoader.pm line 191.
      [Thu Mar 01 18:51:47 2012] [error] [client 172.22.15.177]  at (eval 13) line 3
      [Thu Mar 01 18:51:47 2012] [error] [client 172.22.15.177] Compilation failed in require at (eval 13) line 3.
      [Thu Mar 01 18:51:47 2012] [error] [client 172.22.15.177] Perhaps a required shared library or dll isn't installed where expected
      [Thu Mar 01 18:51:47 2012] [error] [client 172.22.15.177]  at /var/www/web_sites/htdocs/cgi-bin/oracle_test.pl line 27
      For one thing, I'm not sure why it's looking for libclntsh.so.10.1, when i have OIC v11 installed. But I symlinked the libclntsh.so file via libclntsh.so.10.1, which is enabling my script to run from the command line.

      But it's still not working thru Apache.

      I confirmed that all the environment variables are set correctly - tho I have to set them explicitly in my Perl script - for some reason it's not picking them up in my envvars file... just the PATH variable.

      Any ideas?