mac下安装oci8扩展来支持php连接oracle

/ 0评 / 7

下载oci8扩展包:
http://pecl.php.net/package/oci8

cd到解压目录执行phpize,发现错误,

错误提示:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

解决方法:
curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gztar xzf autoconf-latest.tar.gz
cd autoconf-*./configure --prefix=/usr/local
make
sudo make install

phpize后继续安装
./configure --with-php-config=[php-config路径]

一个警告:
WARNING: OCI8 extension: ORACLE_HOME is not set, looking for default Oracle Instant Client instead
checking Oracle Instant Client directory... configure: error: Oracle Instant Client directory /usr/lib/oracle/.../client64/lib libraries not found. Try --with-oci8=instantclient,DIR
看来还得装oracle客户端。
去http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html下载
instantclient-basic-macos.x32-11.2.0.4.0.zip
instantclient-sqlplus-macos.x32-11.2.0.4.0.zip
instantclient-sdk-macos.x32-11.2.0.4.0.zip

三个文件解压后放到同一文件夹内,全部移动到/usr/local/instantclient_11_2/

创建软连接
sudo ln -s /usr/local/instantclient_11_2/sdk/include/*.h /usr/local/include/
sudo ln -s /usr/local/instantclient_11_2/sqlplus /usr/local/bin/
sudo ln -s /usr/local/instantclient_11_2/*.dylib /usr/local/lib/
sudo ln -s /usr/local/instantclient_11_2/*.dylib.11.1 /usr/local/lib/
sudo ln -s /usr/local/lib/libclntsh.dylib.11.1 /usr/local/lib/libclntsh.dylib

测试一下/usr/local/bin/sqlplus,能运行说明成功了

好吧,继续安装oci8扩展包
./configure --with-php-config=[php-config路径] --with-oci8=instantclient,/usr/local/lib

最后在php.ini文件中加入
extension=oci8.so
重启apache。