[php安装oracle扩展名]PHP安装ORACLE扩展(oic8安装教程)

时间:2019-08-22  来源:php安装  阅读:

本文主要叙述,php环境与oracle数据库不在同一台服务器上时,php环境的安装编译

按照官方说明文档 http://cn2.php.net/manual/zh/oci8.installation.php
编译php的时候要加上这个参数–with-oci8,但是加这个参数有个前提,就是必须要安装了对应的库文件。

安装库文件有两种方法:

一. 你的php环境和oracle在同一台服务器上(通常oracle都很大,这方法不合适)
二. 在你的php服务器上安装 Oracle Instant Client libraries.(这个方法适合php与oracle不在一个服务器上)

Oracle Instant Client libraries的安装步骤:详见 这里
1. 针对自己的系统下载适合的Instant Client packages安装包。其中安装包都需要Basic或者Basic Lite包(根据本链接选择一个系统平台,然后进去下载对应的Basic或者SDK等等包)

这里我下载了三个zip的包,分别是:

 代码如下 Instant Client Package – Basic
Instant Client Package – SQL*Plus
Instant Client Package – SDK

2. 解压包到一个单独的目录,比如 “instantclient”.(我把上述三个包放到一起,然后放到了/usr/local/instantclient)

3. 在环境变量里设置库的加载路径,路径为第二部设置的路径”instantclient”。多数UNIX平台环境变量设置LD_LIBRARY_PATH,而Windows系统应该用PATH

4. 可以开始你的应用了

加载库(上述第3步骤,环境变量)
上述所述的库,需要加载到linux系统才可以,那怎么加载呢
方法一:
编辑 /etc/ld.so.conf,在里面加入一行库文件路径/usr/local/instantclient(根据实际情况而定)
注意:centos的/etc/ld.so.conf文件里是用include包含加载了/etc/ld.so.conf.d/*.conf所有文件,所以我们可以创建一个文件/etc/ld.so.conf.d/oracle.conf,在里面加入一行库文件路径/usr/local/instantclient(根据实际情况而定),而不是直接编辑/etc/ld.so.conf文件。

方法二:

设置Linux系统设置环境变量

 

 代码如下 vim ~/.bashrc

最后一行加入

 代码如下


export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/instantclient

此处根据实际情况修改,因为上述第二步的instantclient位置放到了/usr/local/instantclient

编译PHP
如果是编译安装php则需要加上 –with-oci8参数,因为我把Instant Client packages放在了/usr/local/instantclient
所以–with-oci8参数可以这样写

 代码如下

–with-oci8=shared,instantclient,/usr/local/instantclient

php实例编译如下:

 代码如下
./configure --prefix=/usr/local/php-5.3 --with-config-file-path=/usr/local/php-5.3/etc --with-config-file-scan-dir=/usr/local/php-5.3/etc/php.d --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-openssl --enable-soap --enable-safe-mode --enable-zip --with-oci8=shared,instantclient,/usr/local/instantclient

php官方实例,这样写的./configure –with-oci8=shared,instantclient,/usr/lib/oracle//client/lib
编译时如提示找不到libclntsh.so,可以加个软链

 代码如下

ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so

安装oci8拓展

使用php的pecl安装拓展

 代码如下 ./pecl install oci8

在提示输入,Instant Client packages库的路径时候录入实际路径,此处录入:

 代码如下

shared,instantclient,/usr/local/instantclient
 

[root@localhost bin]# ./pecl install oci8
downloading oci8-2.0.8.tgz ...
Starting to download oci8-2.0.8.tgz (190,854 bytes)
.........................................done: 190,854 bytes
11 source files, building
WARNING: php_bin /usr/local/php-5.3/bin/php appears to have a suffix -5.3/bin/php, but config variable php_suffix does not match
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
Please provide the path to the ORACLE_HOME directory. Use "instantclient,/path/to/instant/client/lib" if you"re compiling with Oracle Instant Client [autodetect] : shared,instantclient,/usr/local/instantclient

最后把oci8加入php.ini

 代码如下

extension=oci8.so

查看phpinfo

PHP安装ORACLE扩展(oic8安装教程)

[php安装oracle扩展名]PHP安装ORACLE扩展(oic8安装教程)

http://m.bbyears.com/jiaocheng/63716.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新