首页 » Oracle » oracle 10g/11g php扩展(pdo_oci和oci8的安装)

oracle 10g/11g php扩展(pdo_oci和oci8的安装)

 
文章目录

oracle 10g php扩展(pdo_oci和oci8的安装)

首先说明一下安装流程,不管是安装哪个扩展,都要安装oracle对应的客户端,如oracle DB服务端是10.2的,那你就安装10.2的客户端, 第二步安装对应的扩展

pdo_oci和oci8这两个扩展理论上是没有依赖关系,也就是说连oracle数据库只需要用其中一个扩展就可以了。

安装oracle客户端

oracle客户端下载地址

10.2.0.3版本的客户端安装步骤如下:

rpm -ivh oracle-instantclient-basic-10.2.0.3-1.x86_64.rpm
rpm -ivh oracle-instantclient-devel-10.2.0.3-1.x86_64.rpm
#做软链的目的是因为我们是64位系统,32位没有生成,所以做软链生成
ln -s /usr/lib/oracle/10.2.0.3/client64 /usr/lib/oracle/10.2.0.3/client
ln -s /usr/include/oracle/10.2.0.3/client64 /usr/lib/oracle/10.2.0.3/client
#环境变量生成
echo "export ORACLE_HOME=/usr/lib/oracle/10.2.0.3/client64" >>/etc/profile
echo "export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client64/lib" >>/etc/profile
source /etc/profile

11.2版本客户端安装:

$ sudo rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

$ sudo ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11.2/client
$ sudo ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client
#环境变量参考上面10.2的就可以。

上面的安装的程序的环境变量很重要,目的是使其他程序能够换到他。

php的pdo_oci安装

pdo_oci源码下载地址

由于pdo_oci比较老,所以安装10g,11g的客户端,都要修改源码,安装步骤如下:

#修改config.mb4的第10行左右,也就是修改版本号,如下:
9     test -z "$PDO_OCI_VERSION" && PDO_OCI_VERSION=7.3
10   elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.10.2.0.3; then
11     PDO_OCI_VERSION=10.2.0.3 

#101行之后随便找一行修改版本号就可以了
116     10.2.0.3)
117       PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)

#安装步骤如下:
phpize
./configure  --with-pdo-oci=instantclient,/usr,10.2.0.3 --with-php-config=/usr/bin/php-config
make
make install

在make的时候报错

For Red hat 6, 64bits, client 11.2,
After touch config.m4 and tune up libs symlinks..
I get a compilation error "pdo_oci.c:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pdo_oci_functions’"
To solve it just change function_entry to zend_function_entry @pdo_oci.c file.
 
修改文件pdo_oci.c
34行function_entry 改成 zend_function_entry


#查看文件:
ls /usr/lib64/php/modules/pdo_oci.so

假设按以上方法安装configure时报以下错:

checking for oci.h… configure: error: I’m too dumb to figure out where the include dir is in your instant client install

可以按照以下方法安装:

    cd /usr/lib/oracle/10.2.0.3/client64
    mkdir sdk
    cd sdk && ln -s /usr/include/oracle/10.2.0.3/client64 include
    ln -s /usr/lib/oracle/10.2.0.3/client64/sdk/include/ /usr/lib/oracle/10.2.0.3/client/include
    ln -s /usr/lib/oracle/10.2.0.3/client64/ /usr/lib/oracle/10.2.0.3/client
    ln -s /usr/include/oracle/10.2.0.3/client64/ /usr/include/oracle/10.2.0.3/client

然后下载安装:


    pecl download pdo_oci
    tar -xvf PDO_OCI-1.0.tgz
    cd PDO_OCI-1.0
    sed -i -e 's/function_entry pdo_oci_functions/zend_function_entry pdo_oci_functions/' pdo_oci.c
    mkdir include
    ln -s /usr/include/php include/php
    phpize
    cp /usr/include/oracle/10.2.0.3/client64/* ./include
    ./configure --with-pdo-oci=instantclient,/usr,10.2.0.3
    make && make install

参考:https://stackoverflow.com/questions/20342562/php-5-4-compilation-with-pdo-oci-driver-using-oracle-instant-client-10-2-0-4

安装OCI8扩展

oci8下载地址 安装步骤如下:

phpize
./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.3/client64/lib  --with-php-config=/usr/bin/php-config
make 
make install
#有生成oci8.so文件就要以了

如果make有报错: fatal error: oci8_dtrace_gen.h: No such file or directory
修改文件 the file 'php_oci8_int.h', change the 48th line
#include "oci8_dtrace_gen.h" to #undef HAVE_OCI8_DTRACE

错误记录

502

nginx报502,php报以下错:

[17-Sep-2017 19:07:23] NOTICE: [pool www] child 6792 started
[17-Sep-2017 19:14:42] WARNING: [pool www] child 6779 exited on signal 11 (SIGSEGV - core dumped) after 472.007863 seconds from start
[17-Sep-2017 19:14:42] NOTICE: [pool www] child 6861 started
[17-Sep-2017 19:14:43] WARNING: [pool www] child 6780 exited on signal 11 (SIGSEGV - core dumped) after 473.312312 seconds from start
[17-Sep-2017 19:14:43] NOTICE: [pool www] child 6864 started
[17-Sep-2017 19:14:44] WARNING: [pool www] child 6781 exited on signal 11 (SIGSEGV - core dumped) after 474.662363 seconds from start

#开启Debug报以下错:
 1 events
[18-Sep-2017 11:45:15.328111] DEBUG: pid 2894, fpm_got_signal(), line 76: received SIGCHLD
[18-Sep-2017 11:45:15.328120] DEBUG: pid 2894, fpm_children_bury(), line 252: [pool www] child 29
30 exited on signal 15 (SIGTERM) after 1124.519209 seconds from start
[18-Sep-2017 11:45:15.328123] DEBUG: pid 2894, fpm_event_loop(), line 419: event module triggered
 1 events
[18-Sep-2017 11:45:15.328228] DEBUG: pid 2894, fpm_got_signal(), line 76: received SIGCHLD
[18-Sep-2017 11:45:15.328237] DEBUG: pid 2894, fpm_children_bury(), line 252: [pool www] child 29
35 exited on signal 15 (SIGTERM) after 1124.518138 seconds from start
[18-Sep-2017 11:45:15.328240] DEBUG: pid 2894, fpm_event_loop(), line 419: event module triggered
 1 events

解决方法: 在php-fpm.conf下在www.conf下面添加以下环境变量配置

env[LD_LIBRARY_PATH] = /usr/lib/oracle/10.2.0.3/client64/lib
env[ORACLE_HOME] = /usr/lib/oracle/10.2.0.3/client64/

我在11。2g 上安装时配置上面还是报502,后面配置成以下就可以了。

env[LD_LIBRARY_PATH] = /usr/lib/oracle/10.2.0.3/client64/lib
env[ORACLE_HOME] = /usr/lib/oracle/10.2.0.3/client64/lib

原因分析:

  • 报502是由于程序连接不上数据库,或者是扩展程序直接导致php-fpm死了,
  • 环境变量是有加载,但php的运行用户获取不到,导致连接失败,
  • 说明连接数据库用到了oracle客户端相关的库
  • oracle clinet是必须安装的

502,重启之后在访问还是502

nginx和php以及orace都是开机启动,服务器重启之后发现访问网站又报502,但重启一下php又可以访问了。 既然知道是这样就好办了

解决方法: 把启动加入到rc.local就可以了,

su - root -lc "/etc/init.d/php-fpm restart"

这样就可以加载变量了,所以访问就没有问题了。

参考文件有:
http://blog.sina.com.cn/s/blog_57c70e190101cdq1.html

https://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit
http://wzmlj.com/wicub/p/6673160.html

http://blog.sina.com.cn/s/blog_57c70e190101cdq1.html

原文链接:oracle 10g/11g php扩展(pdo_oci和oci8的安装),转载请注明来源!

4