如何在 macOS Catalina 或 Big Sur 上的 PHP 7.4 上安装 OCI8 扩展?

How to install OCI8 extension on PHP 7.4 on macOS Catalina or Big Sur?

我已经通过 Homebrew 在我的 Mac 上安装了 PHP 7.4.11 和 Apache 2.4.46。

然后安装 Oracle 即时客户端和 sqlplus (v19.3.0.0.0):

$ brew tap InstantClientTap/instantclient
$ brew install instantclient-basic
$ brew install instantclient-sqlplus

接下来是安装OCI8扩展,按运行:

pecl install oci8

PECL 提示我:

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] :

我不确定这是什么 /path/to/instant/client/lib,所以我 运行 locate sqplus:

/usr/local/Cellar/instantclient-sqlplus /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/.brew /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/.brew/instantclient-sqlplus.rb /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/INSTALL_RECEIPT.json /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/bin /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/bin/sqlplus /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib/libsqlplus.dylib /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib/libsqlplusic.dylib /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/libexec /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/libexec/sqlplus /usr/local/Homebrew/Library/Taps/instantclienttap/homebrew-instantclient/Formula/instantclient-sqlplus.rb /usr/local/bin/sqlplus /usr/local/lib/libsqlplus.dylib /usr/local/lib/libsqlplusic.dylib /usr/local/opt/instantclient-sqlplus /usr/local/var/homebrew/linked/instantclient-sqlplus

好的,让我们试试这 2 个目录:

/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib

checking Oracle ORACLE_HOME install directory... /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib checking ORACLE_HOME library validity... configure: error: Oracle library directory not found in /usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib ERROR: `/private/tmp/pear/temp/oci8/configure --with-php-config=/usr/local/opt/php/bin/php-config --with-oci8=/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib' failed

/usr/local/lib/

checking Oracle Instant Client directory... /usr/local/lib/ checking Oracle Instant Client SDK header directory... configure: error: Oracle Instant Client SDK header files not found ERROR: `/private/tmp/pear/temp/oci8/configure --with-php-config=/usr/local/opt/php/bin/php-config --with-oci8=instantclient,/usr/local/lib/' failed

/path/to/instant/client/lib 产生了与前者相同的错误。

那么正确的是哪一个?

我个人会安装新的 Instant Client 19.8 DMGs from Oracle. The download page and the packages contain instructions. Also see the steps at Notarized macOS Oracle Instant Client Packages Make Installation Easier。安装 Basic 和 SDK 包 - 如果您也需要,也可以安装 SQL*Plus。您在 PECL 提示符下给出的路径将是 /Users/yourname/Downloads/instanclient_19_8,但如果您想将它放在其他地方,您可以移动该目录。

可能是 brew 包将 header 文件放在 OCI8 安装脚本不知道的地方。通过使用 DMG,将找到 headers。