无法使用Apache/Mod_Perl中的DBD::Oracle

无法使用Apache/Mod_Perl中的DBD::Oracle,oracle,perl,apache,dbi,dbd,Oracle,Perl,Apache,Dbi,Dbd,环境: Startup.pl Red Hat Enterprise Linux Server release 6.4 Apache/2.2.15 (Unix) mod_perl/2.0.4 Perl/v5.10.1 Perl v5.10.1 (*) built for x86_64-linux-thread-multi 64 bit Oracle client for 11.2 DBD::Oracle : Oracle Driver for DBI ; P/PY/PYTHIAN/DBD-Ora

环境:

Startup.pl

Red Hat Enterprise Linux Server release 6.4 
Apache/2.2.15 (Unix) mod_perl/2.0.4 Perl/v5.10.1
Perl v5.10.1 (*) built for x86_64-linux-thread-multi
64 bit Oracle client for 11.2
DBD::Oracle : Oracle Driver for DBI ; P/PY/PYTHIAN/DBD-Oracle-1.64.tar.gz : /usr/local/lib64/perl5/DBD/Oracle.pm : Installed: 1.64 
/home/oracle/app/oracle/product/11.2.0/client_1/lib/libclntsh.so.11.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped 
-rwxr-xr-x. 1 oracle oracle 48725761 Jun 10 17:41 /home/oracle/app/oracle/product/11.2.0/client_1/lib/libclntsh.so.11.1
阿帕奇形态

use lib qw(/home/oracle/app/oracle/product/11.2.0/client_1/lib);
BEGIN {
    $ENV{ORACLE_HOME}     = '/home/oracle/app/oracle/product/11.2.0/client_1';
    $ENV{LD_LIBRARY_PATH} = '/home/oracle/app/oracle/product/11.2.0/client_1/lib';
    $ENV{ORACLE_SID}      = 'MARS';
}
print STDERR "\nORACLE_HOME = " . $ENV{'ORACLE_HOME'} . "\n";
print STDERR "\nLD_LIBRARY_PATH = " . $ENV{'LD_LIBRARY_PATH'} . "\n";

use mod_perl2;
use Apache::DBI ();
use DBI ();
use DBD::Oracle;

BEGIN { use Data::Dumper; print STDERR Dumper(\@INC); }
print STDERR "ModPerl2 Startup.pl\n";
foreach ( keys %ENV ) {
    print STDERR "$_\t$ENV{$_}\n";
}
1;
错误:

PerlRequire /var/www/cgi-bin/startup.pl
SetEnv ORACLE_HOME "/home/oracle/app/oracle/product/11.2.0/client_1"
SetEnv LD_LIBRARY_PATH "/home/oracle/app/oracle/product/11.2.0/client_1/lib"
Startup.pl在从命令行运行时工作,但无法通过Apache加载

事情已经尝试过了

  • 在apacheconf中设置env变量(如上所示)
  • 正在检查oracle库的文件权限
  • 从命令行打印env变量,并在从Apache运行时与输出进行比较(在删除DBD::Oracle之后)
  • 确保所有Perl、Apache、Oracle、DBD:Oracle都适用于64位
  • 将/home/oracle/app/oracle/product/11.2.0/client_1/lib添加到/etc/ld.so.conf并运行ldconf

该错误源于Apache无法找到Oracle安装。将Oracle$PATH环境变量放入bin/envvars文件中,如下所示:

Can't load '/usr/local/lib64/perl5/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.11.1: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 200.\n at /var/www/cgi-bin/startup.pl line 17\nCompilation failed in require at /var/www/cgi-bin/startup.pl line 17.\nBEGIN failed--compilation aborted at /var/www/cgi-bin/startup.pl line 17.\nCompilation failed in require at (eval 2) line 1.\n

您的
DBD::Oracle
是根据11.1构建的,错误消息证明了这一点,它正在寻找一个专门命名/版本控制的.so文件(“libclntsh.so.11.1”)

但是,正如您的路径所证明的,您的运行时是为11.2配置的,并且没有提供专门命名/版本控制的.so文件


为您首选的运行时配置重建
DBD::Oracle
,并从那里开始。

这很可能是一个selinux问题。如果您的脚本在shell中运行良好,但在apache中运行不好,请尝试禁用selinux


如果有帮助,您最好配置selinux,而不是仅仅禁用它。

在RHEL(5、6和7)上有相同的错误消息。这就是最终为我解决的问题:

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# envvars-std - default environment variables for apachectl
#
# This file is generated from envvars-std.in
#
ORACLE_HOME="/home/oracle/app/oracle/product/11.2.0/client_1"
LD_LIBRARY_PATH="/home/oracle/app/oracle/product/11.2.0/client_1/lib"

export LD_LIBRARY_PATH ORACLE_HOME

我从来没有弄清这个问题的根源。构建了不同版本的Apache和ModPerl,并尝试了Oracle客户端的各种组合,直到问题消失。工作组合:Apache/2.2.24(Unix)mod_perl/2.0.7 perl/v5.10.1解决方案没有定论时,我讨厌它。不过,感谢您的关注!这就是我留下来的“从未找到问题的根源。构建了不同版本的Apache和ModPerl,并尝试了各种Oracle客户端组合,直到问题消失。工作组合:Apache/2.2.24(Unix)mod_perl/2.0.7 perl/v5.10.1”谢谢
echo $ORACLE_HOME/lib >> /etc/ld.so.conf
/sbin/ldconfig
service httpd stop; service httpd start