在CentOS 6.7 64位安装PHP的PDO_OCI扩展 Installing PDO_OCI extension on CentOS 6.7 64bit
需求&背景
最近根据项目需求,要在php中远程连接Oracel 11g Express数据库,为了开发方便,决定采用pdo,也就是php的PDO_OCI扩展,但是php安装的时候并没有安装PDO_OCI扩展,所以现在需要新增一个php扩展。
解决方案
首先上google搜索了一下,找到一片文章:http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/, 这篇文章讲的很详细,非常感谢作者!
我在这里再简略总结一下:
首先要安装Oracle数据库的InstantClient: 下载地址:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html。根据自己的系统,选择合适的安装包,Basic和devel两个包都需要安装。因为我的服务器上并没有安装Oracle 11g Express数据库,所以需要安装, 如果服务器上已经装好了Oracle 11g Express数据库, 这一步应该是可以忽略的(仅仅是一个猜测,没有测试)
从pear下载PDO_OCI的源码包 (https://pecl.php.net/package/PDO_OCI), 选择1.0的stable版本即可, 可以使用wget直接下载到linux, 或者使用pecl命令(推荐):
$ pecl download PDO_OCI
$ tar -xvf PDO_OCI-1.0.tgz
$ cd PDO_OCI-1.0因为PDO_OCI这个扩展已经很久没有更新了,需要编辑config.m4这个文件以支持11g或者更高版本的数据库, 具体如下:
在第10行左右添加如下代码:
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then
PDO_OCI_VERSION=11.2在101行左右添加如下代码:
11.2)
PHP_ADD_LIBRARY(clntsh, , PDO_OCI_SHARED_LIBADD)
;;然后就是用phpize这个工具进行编译安装:
$ phpize
//如果系统提示没有找到这个命令,只需要安装php-devel即可
//$ yum install php-devel
$ ./configure --with-pdo-oci=instantclient,/usr,11.2
$ make
$ sudo make install我在运行 ./configure --with-pdo-oci=instantclient,/usr,11.2后得到一个错误: checking for oci.h... configure: error: I'm too dumb to figure out where the include dir is in your instant client install 意思是说, 没有找到instant client 的include 文件夹, 这是为什么呢?继续google, 这个问题不多见,我花了很多时间在这个问题上面。最后看到一片文章下的评论:
Changes for x86_64 November 10th 2010 at 09:11 am Some changes were required to get the configure to work on a 64 bit Redhat (Fedora 13) system.
We installed the 64 bit version of oracle-instantclient-{devel,basic}.
These installed in:
/usr/lib/oracle/11.2/client64
/usr/include/oracle/11.2/client64We created symlinks as follows:
/usr/lib/oracle/11.2/client -> /usr/lib/oracle/11.2/client64
/usr/include/oracle/11.2/client -> /usr/include/oracle/11.2/client64Then the "./configure --with-pdo-oci=instantclient,/usr,11.2" command worked fine!
The reason for the symlinks instead of changing the variables in the oracle.sh is that the build/configure scripts seem to be hard coded for "client" (not client64) in many places. It was easer to create 2 symlinks than to change all the code in every script/config file.
非常感谢这问网友。大概意思是在configure时查找的文件夹是/usr/lib/oracle/11.2/client 和/usr/include/oracle/11.2/client, 这两个文件夹位置的组成方式是:${prefix}/lib OR lib/oracle/${version}/client,而64bit 的Instant Client的安装目录都是client64,所以configure的时候找不到,解决这个问题只需要添加两个符号链接即可:
$ 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添加好符号链接后,再次执行
$ ./configure --with-pdo-oci=instantclient,/usr,11.2
$ make
$ sudo make install执行成功, 没有报错。
make install 成功之后,在 /usr/lib64/php/modules/ 就会出现pdo_oci.so,然后在php的配置文件中激活pdo_oci扩展:
$ vi /etc/php.d/pdo_oci.ini
添加内容: extension=pdo_oci.so
重启apache就可以使用PDO_OCI扩展了。
如果您觉得阅读本文对您有帮助,欢迎转载本文,但是转载文章之后必须在文章页面明显位置保留此段声明,否则保留追究法律责任的权利。
作 者:blog.jpdou.top
原文链接:http://blog.jpdou.top/install-pdo_oci-extension-on-linux-64bit/
最新文章
- 临时解决系统中大量的TIME_WAIT连接
- suspendlayout
- HTTP与HTTPS握手的那些事
- 魅族MX3\MX2 在MTP模式下恢复手机误删数据教程
- 【kAri OJ605】陈队的树
- VHD更新命令(打补丁)
- 20160502-struts2入门--国际化
- Java语言基础(五)
- chartControl 饼状图小Demo
- JEMETER 录制
- MVC调用部分视图PartialView
- Material使用01 侧边栏MdSidenavModule、工具栏MdTollbarModule
- 内部类访问局部变量为什么必须要用final修饰
- 案例学编程系列:案例认识 Spring IOC
- Java语法之注解
- CRM JS
- C++ 多态Polymorphism 介绍+动态绑定、静态绑定
- Megcup2017 Dogfood
- 01.基于IDEA+Spring+Maven搭建测试项目--综述
- lua协程----ngx-lua线程学习笔记
热门文章
- oracle获取一段时间内所有的小时、天、月
- 是否要从单片机转为嵌入式Linux?
- Docker运行MongoDB及Redis及ssh端口映射远程连接
- Ubuntu解压windows下的.zip文件出现乱码的解决办法
- error:: undefined reference to symbol '__glewBufferSubData' 未定义的引用 以及 error: main.o: undefined reference to symbol 'glTexImage2D'
- python如何实现相对导入
- tcp/ip详解(转)
- python读写mysql总结
- 11.ClientCredential模式总结
- 《剑指offer》面试题5—从尾到头打印链表