一、安装oracle客户端
1. 首先去oracle官网下载三个客户端的包
oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
官网有个问题,下载速速很慢,不能翻墙或者下载慢的可以去360云盘下载
https://yunpan.360.cn/surl_ycn8isDGr7U (提取码:020b)
2. 执行安装命令
rpm -ivh oracle-instantclient12.2-*
3. 添加环境变量
[root@localhost ~]# vim /etc/profile
## 在尾部增加如下内容
export ORACLE_HOME=/usr/lib/oracle/12.2/client64
export ORACLE_BASE=/usr/lib/oracle/12.2
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH
保存退出后执行:source /etc/profile
二、安装oci8的php扩展
1. 方法一:pecl安装
pecl install oci8
.....
期间会出现:
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,/usr/lib/oracle/12.2/client64/lib
....
验证是否安装成功
[root@localhost src]# php -m | grep oci8
oci8
重启php-fpm服务
/etc/init.d/php-fpm restart
2. 方法二:编译安装
分别执行如下命令:
[root@localhost src]# wget http://pecl.php.net/get/oci8-2.1.8.tgz
[root@localhost src]# tar xzvf oci8-2.1.8.tgz
[root@localhost src]# cd oci8-2.1.8
[root@localhost oci8-2.1.8]# phpize
[root@localhost oci8-2.1.8]# ./configure --with-oci8=instantclient,/usr/lib/oracle/12.2/client64/lib
[root@localhost oci8-2.1.8]# make && make install
# php.ini中增加扩展引入
[root@localhost oci8-2.1.8]# vim /etc/php.d/oci8.ini
extension=oci8.so
## 验证是否成功
[root@localhost oci8-2.1.8]# php -m | grep oci8
oci8
至此,oci8的php扩展安装成功,祝大家使用oracle愉快!