centos 安装Oracle php扩展_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > centos 安装Oracle php扩展

centos 安装Oracle php扩展

 2017/11/25 17:50:32  nbczw8750  程序员俱乐部  我要评论(0)
  • 摘要:一.准备文件(1)oracle客户端rpm包下载地址http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html下载如下两个文件(下载文件需注册哦):oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpmoracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm(2)扩展文件下载,有两种方式
  • 标签:PHP ORA 安装 Oracle CentOS

一.准备文件

? ? ? (1)oracle客户端rpm包下载地址

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

? ? ? 下载如下两个文件(下载文件需注册哦):

? ? ? ?oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm

? ? ? oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

? ? ? (2)扩展文件下载,有两种方式,第一种是下载单独的扩展文件,一种是直接下载PHP源码,在ext文件夹中有对应的扩展文件夹,以下我们以第二种方式给大家介绍。

? ? ? ?http://pecl.php.net/package/PDO_OCI ? ? PDO_OCI-1.0.tgz ? ? ?Oracle Call Interface driver for PDO

? ? ? ?http://pecl.php.net/package/oci8 ? ? ? ?oci8-1.4.5.tgz ? ? ? Extension for Oracle Database,allows you to access Oracle databases

? ? ? ?http://www.php.net/downloads.php ? 下载你本机对应版本的PHP

?

二、安装及配置Oracle客户端

? ? ? 1.安装

?

class="sh" name="code">#rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm  
#rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm  

?以下几条rpm相关命令供参考:

?

?

rpm -qa | grep oracle                                                   //查看oracle是否安装  
rpm -qa                                                                 //查看所有已安装的人rpm包  
rpm -e oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm           //卸载已安装的rpm包  
rpm -ivh --force oracle-instantclient11.2-basic-11.2.0.3.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

?

?

三、安装pdo_oci模块

? ? 1.准备工作

?

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

?

?

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 

?

?

? 2.安装

? ? 进入对应的扩展文件夹,例如/php/ext/php_oci

? ?然后开始安装

?

?

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-oci=instantclient,/usr,10.2.0.1
make && make install

??可看到php_oci.so已在文件夹中

?

?

? 3.配置

?

? ? ? ?有两种方法,其一,直接在php.ini中打开扩展,其二,在php.d文件夹中添加对应的ini文件及内容

?

#vi /etc/php.ini  
extension=pdo_oci.so  //在php.ini中加入此行  
  
 或者直接在命令行输入  
  
echo 'extension=pdo_oci.so' > /etc/php.d/pdo_oci.ini 

?

?

四、安装oci8模块

?

? ?1.安装

? ?进入对应的扩展文件夹,开始安装

?

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config -with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client/lib
make && make install

?

?

? ? 可看到oci8.so已在文件夹中

?

? ??2.配置

? ? ?有两种方法,其一,直接在php.ini中打开扩展,其二,在php.d文件夹中添加对应的ini文件及内容

?

#vi /etc/php.ini  
  
extension=oci8.so    //在php.ini中加入此行  
  
或者直接在命令行输入  
  
echo 'extension=oci8.so' > /etc/php.d/oci8.ini  

? ?最后重启apache即可。phpinfo()可看到,php_oci及oci8扩展均已成功开启

?

?

?

? Server Version Client Version 12.2.0#10 12.1.0 11.2.0 11.1.0 10.2.0 10.1.0 9.2.0 9.0.1 8.1.7 8.1.6 8.1.5 8.0.6 8.0.5 7.3.4 12.2.0 Yes Yes Yes No No No#3 No#3 No#3 No#3 No#3 No#3 No#3 No#3 No#3 12.1.0 Yes Yes Yes Was MDS#7 No#3 No#3 No#3 No#3 No#3 No#3 No#3 No#3 No#3 11.2.0 Yes#9 Yes Yes Was MDS#7 No Was#5 No#3 No#3 No#3 No#3 No#3 No#3 No#3 11.1.0 No Was Was Was Was#7 Was#6 Was#5 No#3 No#3 No#3 No#3 No#3 No#3 No#3 10.2.0 No MDS#7 MDS#7 Was#7 MDS Was Was#5 No Was No#3 No#3 No#3 No#3 No#3 10.1.0#4 No No Was#6 Was#6 Was Was Was Was Was #2 No#3 No#3 No#3 No#3 No#3 9.2.0 No No#8 Was#5 Was#5 Was#5 Was Was Was Was No No Was No No#1 9.0.1 No No No No No Was Was Was Was Was No Was No Was 8.1.7 No No No No Was Was Was Was Was Was Was Was Was Was 8.1.6 No No No No No No No Was Was Was Was Was Was Was 8.1.5 No No No No No No No No Was Was Was Was Was Was 8.0.6 No No No No No No Was Was Was Was Was Was Was Was 8.0.5 No No No No No No No No Was Was Was Was Was Was 7.3.4 No No No No No No Was Was Was Was Was Was Was Was ?
? ?

六.错误及解决方案

?

? ? ?1.checking for oci.h... configure: error: I'm too dumb to figure out where the include dir is in your Instant Client install

?

? ? ? 解决方法:检查--with-oci8,--with-pdo-oci的路径是否正确

?

? ? 2.configure: error: Oracle Instant Client SDK header files not found

?

? ? ?解决方法:是否是sdk文件未安装,即rmp文件名中包含devel的文件,确认是否安装成功。

?

? ? 如果确定已安装,可能是以下问题产生的,可能是你PHP的版本过低,我的PHP版本是PHP Version 5.1.6出现此问题之后,百思不得其解,各种查资料也找不到答案。

?

? ? 两个解决方案:

?

? ? 第一,将你的PHP版本升级,至少升到>=5.2.6

?

? ? 第二,我前面说过,可以自行去下载扩展文件,我下载了oci8 1.4.5之后安装成功。

??

? 3.错误代码:

?SQLSTATE[HY000]: OCIEnvNlsCreate: Check the character set is valid and that PHP has access to Oracle libraries and NLS data?

? 修改php-fpm.conf , 加入如下两行代码 注意路径需要根据自己的修改

;Oracle连接环境变量  
env[ORACLE_HOME] =/usr/lib/oracle/12.1/client64  
env[LD_LIBRARY_PATH] = /usr/lib/oracle/12.1/client64/lib 

?

?

参考网站

http://blog.csdn.net/a82168506/article/details/11763989?centos下为php开oracle扩展

?

http://blog.csdn.net/youngqj/article/details/52061851

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

?

上一篇: 自我总结和学习表单提交的几种方式 (一) 下一篇: 没有下一篇了!
发表评论
用户名: 匿名