简体   繁体   English

无法从Apache / Mod_Perl使用DBD :: Oracle

[英]Unable to use DBD::Oracle from Apache/Mod_Perl

Env: 信封:

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

Startup.pl Startup.pl

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;

Apache conf 阿帕奇conf

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"

Error: 错误:

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

Startup.pl works when run from the command line, but fails to load through Apache 从命令行运行时,Startup.pl可以工作,但是无法通过Apache加载

Things already tried 事情已经尝试过

  • Setting env variables in Apache conf (shown above) 在Apache conf中设置环境变量(如上所示)
  • Checking file permisison for oracle libraries 检查Oracle图书馆的文件权限
  • Printing env variables from command line and comparing with the output when running from Apache (after removing DBD::Oracle) 从命令行打印环境变量,并从Apache运行时与输出进行比较(删除DBD :: Oracle之后)
  • Making sure all of Perl, Apache, Oracle, DBD:Oracle are for 64 bit 确保所有Perl,Apache,Oracle,DBD:Oracle都适用于64位
  • Adding /home/oracle/app/oracle/product/11.2.0/client_1/lib to /etc/ld.so.conf and running ldconf 将/home/oracle/app/oracle/product/11.2.0/client_1/lib添加到/etc/ld.so.conf并运行ldconf

That error comes from Apache being unable to find the Oracle installation. 该错误源于Apache无法找到Oracle安装。 Put your Oracle $PATH env vars in the bin/envvars file, like so: 将您的Oracle $ PATH env vars放入bin / envvars文件,如下所示:

# 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

Your DBD::Oracle was built against 11.1 as evidenced by the error message, and it is looking for a specifically named/versioned .so file ("libclntsh.so.11.1"). 错误消息表明,您的DBD::Oracle是针对11.1构建的,并且它正在寻找专门命名/版本化的.so文件(“ libclntsh.so.11.1”)。

Your runtime, however, is configured for 11.2, as evidenced by your paths, and does not supply that specifically named/versioned .so file. 但是,您的运行时已配置为11.2(由路径证明),并且不提供专门命名/版本化的.so文件。

Rebuild DBD::Oracle for your preferred runtime configuration and go from there. 为您首选的运行时配置重建DBD::Oracle ,然后从那里开始。

It can well be a selinux issue. 这很可能是selinux的问题。 If your script runs well from shell but not from apache, try to disable selinux. 如果您的脚本在shell上运行良好,但在apache上运行不好,请尝试禁用selinux。

If it helps, you'd better CONFIGURE selinux instead of just disabling it. 如果有帮助,您最好配置selinux,而不只是禁用它。

Had the same error message on RHEL (5, 6 and 7). 在RHEL(5、6和7)上有相同的错误消息。 This is what finally fixed it for me: 这是最终为我解决的问题:

echo $ORACLE_HOME/lib >> /etc/ld.so.conf
/sbin/ldconfig
service httpd stop; service httpd start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM