您的位置:首页 > 运维架构 > Linux

CENTOS6下PHP5.6的安装 oci8 pdo-oci

2015-11-10 22:34 721 查看
服务器是yum配置的amp环境,本着不重新编译的原则去操作。本机已有环境为PHP,apache,mysql,需要连oracle数据库,所以需要打开oracle扩展。我们需要做的工作有:安装oracle客户端、pdo_oci扩展、oci8扩展。

前期准备工作:

$ sudo yum install php-pear php-devel zlib zlib-devel bc libaio glibc
$ sudo yum groupinstall "Development Tools"

因为扩展还是需要重新编译,所以对编译器也进行了,更新。

yum install gcc-c++
yum install gcc-g77

目标数据库是11g,去Oracle官网下载对应版本(没搞过oracle至少我们这么理解的),

官网下载地址:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

下载文件:

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

php扩展文件下载:

http://pecl.php.net/package/PDO_OCI PDO_OCI-1.0.tgz Oracle的PDO接口

http://pecl.php.net/package/oci8 oci8-2.0.8.tgz
Oracle扩展

安装:

安装Oraclecient

技巧:

rpm -qpl 可以查看rpm包会在哪些路径安装文件

1.安装rpm包

rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

以下几条命令仅供参考:

rpm -qa | grep oracle     //查看oracle是否安装
rpm -qa   //查看所有已安装的人rpm包
rpm -e oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm //卸载已安装的rpm包
rpm -ivh --force oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm //强制安装rpm包

2. 配置

修改/etc/ld.so.conf 或在ld.so.conf.d文件夹下添加oracle-x86_64.conf文件,写入安装oracle客户端的lib路径:

#vi /etc/ld.so.conf
/usr/lib/oracle/11.2/client64/lib/     //加入此行,保存退出

或者

echo '/usr/lib/oracle/11.2/client64/lib/' > /etc/ld.so.conf.d/oracle-x86_64.conf

64位系统需要创建32位的软链接(这里可能是一个遗留bug,不然后面编译会出问题)

ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client
ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11.2/client

定义环境变量

vi etc/profile

加入以下几行

export ORACLE_HOME=/usr/lib/oracle/11.2/client64/
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64:$LD_LIBRARY_PATH
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"

命令行输入以下语句使环境配置立即生效

#source /etc/profile


据说还可以这样,仅供参考:

Create a file inside /etc/profile.d named oracle.sh and put this as the content:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib


And run it so we’ll have LD_LIBRARY_PATH as an environment variable.
source /etc/profile.d/oracle.sh



安装oci8

编译的时候会出现错误:

error: oci8_dtrace_gen.h: No such file or directory

如果需要 DTRACE:
yum install systemtap-sdt-devel
export PHP_DTRACE=yes


如果不需要 DTRACE:
modify the file 'php_oci8_int.h', change the 48th line

#include "oci8_dtrace_gen.h" to #undef HAVE_OCI8_DTRACE


一切就绪,编译安装

tar -xvf oci8-2.0.8.tgz
cd oci8-2.0.8.tgz

/usr/bin/phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
make
make install

在/etc/php.d目录下增加配置文件20-oci8.ini

extension=oci8.so

用下面命令查看是否成功:

php -i | grep oci8

你可以看到下面类似的内容:

/etc/php.d/oci8.ini, oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100 oci8.events => Off => Off oci8.max_persistent => -1 => -1 oci8.old_oci_close_semantics => Off => Off oci8.persistent_timeout => -1 => -1 oci8.ping_interval => 60 => 60 oci8.privileged_connect => Off => Off oci8.statement_cache_size => 20 => 20


安装PDO_OCI

tar -xvf PDO_OCI-1.0.tgz
cd PDO_OCI-1.0


防止pdo_oci对oracle11支持不足(pdo_oci可能不支持oracle11g,需要做个软链接成作为oracle10版本才能编译过去):

ln -s /usr/include/oracle/11.2 /usr/include/oracle/10.2.0.1
ln -s /usr/lib/oracle/11.2 /usr/lib/oracle/10.2.0.1


还可以:

Inside the PDO_OCI-1.0 folder, edit the file named config.m4.

Find a pattern like this near line 10 and add these 2 lines:

elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then
PDO_OCI_VERSION=11.2

Find a pattern like this near line 101 and add these lines:

11.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;


编译的时候我还遇到了其他问题

pdo_oci.c:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pdo_oci_functions’

在pdo_oci.c文件中

将 function_entry 改成 zend_function_entry

一切就绪,开始编译安装

/usr/bin/phpize
./configure --with-pdo-oci=instantclient,/usr,11.2
make
make install

在 /etc/php.d 目录下 新建文件
30-pdo_oci.ini

写入

extension=pdo_oci.so

用下面命令查看是否安装成功

php -i | grep oci


你会见到类似下面的内容

/etc/php.d/pdo_oci.ini,
PDO drivers => oci, odbc, sqlite


至此结束,请运行phpinfo()看看吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: