一、安装Oracle Client
yum -y install gcc
下载instantclient
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
这里我选择的12.2
开始安装,执行命令
rpm -ivh oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
rpm -ivh oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
rpm -ivh oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
echo '/usr/lib/oracle/12.2/client64/lib/' > /etc/ld.so.conf.d/oracle-x86_64.conf #配置Oracle搜索加载动态库
ldconfig
ln -s /usr/lib/oracle/12.2/client64 /usr/lib/oracle/12.2/client
ln -s /usr/include/oracle/12.2/client64 /usr/include/oracle/12.2/client
mkdir -p /usr/lib/oracle/12.2/network/admin
二、设定Oracle Client
echo 'export ORACLE_HOME=/usr/lib/oracle/12.2/client64/' >> /etc/profile
echo 'export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64:$LD_LIBRARY_PATH' >> /etc/profile
echo 'export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"' >> /etc/profile
echo 'export PATH=$PATH:$ORACLE_HOME/bin' >> /etc/profile
echo 'export TNS_ADMIN=/usr/lib/oracle/12.2/network/admin' >> /etc/profile
source /etc/profile
三、php安装oci8扩展
3.2 编译安装
wget https://pecl.php.net/get/oci8-2.2.0.tgz
tar zxvf oci8-2.2.0.tgz
cd oci8-2.2.0
phpize
./configure --with-php-config=php-config --with-oci8=shared,instantclient,/usr/lib/oracle/12.2/client/lib
make && make install
cd ..
ll /usr/lib64/php/modules
echo 'extension=oci8.so' > /etc/php.d/oci8.ini
3.2 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] :
输入:
shared,instantclient,/usr/lib/oracle/12.2/client64/lib
回车
注意后面连接可能会因为oracle源的版本不同而不同
四、手动添加oci8扩展
举例:
touch /etc/php.d/oci8.ini
echo 'extension = oci8.so' > /etc/php.d/oci8.ini
查看结果
php -m | grep oci8
五、重置fpm或web服务
错误处理
错误1:/tmp/oci8/php_oci8_int.h:46:29: fatal error: oci8_dtrace_gen.h: No such file or directory
解决:
如果需要 DTRACE:
yum install systemtap-sdt-devel
export PHP_DTRACE=yes
如果不需要 DTRACE:
modify the file 'php_oci8_int.h', change the 48th line
#include "oci8_dtrace_gen.h" to #undef HAVE_OCI8_DTRACE
如果还有错你不妨换一个版本试试。。。