fedora和ubuntu下oci8的安装方法

来源:互联网 发布:中国西方古典音乐 知乎 编辑:程序博客网 时间:2024/04/29 19:01

ubuntu下

一、基本安装
具体安装过程可以参考http://www.ubuntu.org.cn上的文档。
二、安装Oracle XE client
以能够使用sudo的普通用户登陆并编辑apt源列表文件

sudo vi /etc/apt/sources.list

在sources.list文件中加入下面行

deb http://oss.oracle.com/debian unstable main non-free

存盘退出并执行下面命令:

sudo groupadd oracle; sudo groupadd dba

sudo useradd -d /home/oracle -g oracle -G dba -m -s /bin/bash oracle

sudo apt-get update

sudo apt-get install bc libaio

sudo apt-get install oracle-xe-client

安装oracle-xe-client需要至少1G的虚拟内存。安装好oracle-xe-client后,oracle用户还需配置一下各种环境参数,可以利用

/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin/oracle_env.sh

进行设置或者直接把环境参数添加到自己的.bash_profile文件中去。

在安装完client后,应运行sqlplus连接Oracle数据库来验证一下client安装的正确与否。

将oracle-instantclient-devel-10.2.0.4-1.i386.zip解压来的SDK拷贝到ORACLE_HOME下,安装oci8时需要client header。

三、安装PHP oci8 extension

还是以能够使用sudo的普通用户身份运行下面命令:

sudo apt-get install build-essential

sudo apt-get install php5-dev php-pear

sudo pecl install oci8

在下列提示后先输入一次all然后回车,第二次输入$ORACLE_HOME的实际路径然后回车(我自己的是/usr/lib/oracle/xe/app/oracle/product/10.2.0/client,注意不要输入instantclient,),第三次直接敲回车:

sail@ubuntu:~$ sudo pecl install oci8

downloading oci8-1.2.2.tgz ...

Starting to download oci8-1.2.2.tgz (71,806 bytes) .................done: 71,806 bytes

10 source files, building

running: phpize

Configuring for:

PHP Api Version: 20041225

Zend Module Api No: 20050922

Zend Extension Api No: 220051025

Please provide the path to ORACLE_HOME dir. Use 'instantclient,/path/to/instant/client/lib' if you're compiling against Oracle Instant Client [autodetect] :

在系统编译安装好以后,应该在/usr/lib/php5/20051025(我的php是5.1.6版本的)目录下有一个oci8.so文件。之后执行命令:

sudo vi /etc/php5/apache2/php.ini

在相应位置加上

extension=oci8.so

存盘退出后重启apache2

sudo /etc/init.d/apache2 restart


fedora下

OCI8是PHP对ORACLE数据库的支持模块
安装OCI8之前,需要先装oracle的客户端库文件
Instant Client Package - Basic
以及 Instant Client Package - SDK
安装所有所需文件最方便的方法是使用 Oracle Instant Client,可以从此处得到:http://www.oracle.com/technology/tech/oci/instantclient /instantclient.html.要使 OCI8 模块能工作,”basic” 版的 Oracle Instant Client 已经足够.Instant Client 不需要 ORACLE_SID 或 ORACLE_HOME 环境变量被设定.不过可能还是要设定 LD_LIBRARY_PATH 和 NLS_LANG

rpm -ivh oracle-instantclient-basic-11.1.0.1-1.i386.rpm

rpm -ivh oracle-instantclient-devel-11.1.0.1-1.i386.rpm

 

然後在 .bashrc 的最後面加上

export ORACLE_HOME=/usr/lib/oracle/10.2.0.3/client

 

檢查一下php-pear和php-devel有沒有裝上,pecl命令只有装完php-pear才会有
# pecl install oci8
downloading oci8-1.3.4.tgz …
Starting to download oci8-1.3.4.tgz (134,240 bytes)
……………..done: 134,240 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
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] :

這邊他說如果你是用instantclient 的話,你要特別註明,所以回答會像下面這樣:
instantclient,/usr/lib/oracle/10.2.0.3/client/lib

然後就是像平常在make的時候一樣

安裝成功的話他會出現以下提示:
Build process completed successfully
Installing ‘/var/tmp/pear-build-root/install-oci8-1.3.4//usr/lib/php/modules/oci8.so’
install ok: channel://pecl.php.net/oci8-1.3.4
You should add “extension=oci8.so” to php.ini

照他的提示把extension=oci8.so加到php.ini裡就好了