先需要安装 instantclient(连接 Oracle 数据库的简单客户端),然后编译安装 php-oci8 扩展。
安装 Oracle Instance Client
查询系统是否已经安装 instanceclient:
sudo yum list installed | grep instantclient
从第 3、4 链接下载相应版本的 instanceclient rpm 包文件。使用 yum install
命令安装:
yum install oracle-instantclient-basic-21.3.0.0.0-1.x86_64.rpm
增加 PATH 环境变量:
export PATH=/usr/lib/oracle/21/client64/bin:$PATH
编译安装 oci8
从第 6 链接下载 oci8 源码包,并进行编译安装:
tar xvf oci8-3.0.1.tgz
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib --with-php-config=/www/server/php/80/bin/php-config
make
make install
上面的
/usr/lib/oracle/11.2/client64/lib
、/www/server/php/80/bin/php-config
的路径不能错。
php.ini 增加启用 oci8
扩展,
vi /www/server/php/80/etc/php.ini
[oci8]
extension = oci8.so
检查是否安装成功:
[root@localhost oci8-3.0.1]# php --ri oci8
oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 3.0.1
Oracle Run-time Client Library Version => 11.2.0.4.0
Oracle Compile-time Instant Client Version => 11.2
Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value
oci8.events => Off => Off
Statistics =>
Active Persistent Connections => 0
Active Connections => 0
或者
[root@localhost oci8-3.0.1]# php -m |grep oci8
oci8
编译安装 pdo_oci
pdo_oci 扩展在 php 源码包里。因此在 https://www.php.net/releases/ 里找到已经安装好的 php 版本,并下载源码包,进行编译安装:
wget https://www.php.net/distributions/php-8.0.10.tar.xz
tar xvf php-8.0.10.tar.xz
cd php-8.0.10
cd ext/pdo_oci
phpize
./configure --with-pdo-oci=instantclient,/usr/lib/oracle/11.2/client64/lib --with-php-config=/www/server/php/80/bin/php-config
再在 php.ini 文件里添加并启用 pdo_oci.so
扩展。
[root@localhost pdo_sqlsrv-5.9.0]# php --ri pdo_oci
PDO_OCI
PDO Driver for OCI 8 and later => enabled
参考链接
1、php oci扩展、oracle客户端安装问题及解决
2、Installation of Oracle extensions for PHP
3、Oracle Instant Client Downloads for Linux x86-64 (64-bit)
4、Installing Oracle Instant Client Using RPMs
5、Oracle Instant Client Downloads
6、oci8 - Extension for Oracle Database
7、oci8 Installation - PHP Manual
8、PHP Releases
9、linux下安装php扩展pdo_oci和oci8