无法加载动态库 'oci8.so' (PHP 7.2)

Unable to load dynamic library 'oci8.so' (PHP 7.2)

自从PHP 7.1更新到PHP 7.2后,我无法安装oci8。我有这个错误:

root@3ab6027c8d95:/var/www# php -v

PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so (libmql1.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP 7.2.0 (cli) (built: Dec 12 2017 05:52:58) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.2.0, Copyright (c) 1999-2017, by Zend Technologies

我正在使用 Docker 环境,我为此创建了一个 github 存储库,如果我使用 [=29] 的 7.1 版本就可以了=] (shenron/docker-php-fpm:7.2).

我不明白脚本为何尝试启动此文件:/usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so.so

在我看来有两种可能性;或者驱动不兼容,或者pecl今天安装不了oci8。

有没有人遇到同样的问题?

感谢您的帮助。

/usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so.so 只是对共享库文件名的第二次猜测。您可以放心地忽略它。

实际问题是:(tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so (libmql1.so: cannot open shared object file: No such file or directory)

oci8.so本身依赖多个共享库,可以用ldd找出哪些:

ldd /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so
    linux-vdso.so.1 (0x00007ffc8bfe7000)
    libclntsh.so.12.1 => /usr/local/instantclient/libclntsh.so.12.1 (0x00007fb9919e0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb991641000)
    libmql1.so => not found
    libipc1.so => not found
    libnnz12.so => not found
    libons.so => not found
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb99143d000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb991139000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb990f1c000)
    libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fb990d04000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb990afc000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb994bc8000)
    libaio.so.1 => /lib/x86_64-linux-gnu/libaio.so.1 (0x00007fb9908fa000)
    libclntshcore.so.12.1 => not found

那些 .so 文件似乎是您存储库中 zip 文件的一部分。 运行 PHP 像这样 LD_LIBRARY_PATH=/usr/local/instantclient_12_1/ php 在你的容器中工作正常。您需要将那些 so 文件移动到一个合理的位置。

对于遇到这个问题的任何人,这里是 linux 中处理它的正确方法。 (我在下面的演示中使用 CentOS 命令,但 Ubnutu 应该没有什么不同)

第 1 步:获取 Oracle 库

编辑:感谢克里斯托弗·琼斯的评论,您可以在 https://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/

找到直接的 rpm 链接
wget oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm 
wget oracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm 

第 2 步:安装

yum install oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm
yum install  oracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm 

第 3 步:配置(使 oracle 库的路径可被发现)

sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle.conf"
sudo ldconfig

测试

php -v
# and you should get something like
PHP 7.2.12 (cli) (built: Nov  6 2018 16:40:25)...

如果 运行ning ldd /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so 给你这样的东西,缺少文件:

ldd /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so
    linux-vdso.so.1 (0x00007ffc8bfe7000)
    libclntsh.so.12.1 => /usr/local/instantclient/libclntsh.so.12.1 (0x00007fb9919e0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb991641000)
    libmql1.so => not found
    libipc1.so => not found
    libnnz12.so => not found
    libons.so => not found
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb99143d000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb991139000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb990f1c000)
    libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fb990d04000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb990afc000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb994bc8000)
    libaio.so.1 => /lib/x86_64-linux-gnu/libaio.so.1 (0x00007fb9908fa000)
    libclntshcore.so.12.1 => not found

您可以像这样将文件夹添加到您的 ldconfig(其他读者 - 您的路径可能会有所不同):

echo /usr/local/instantclient_12_1/ > /etc/ld.so.conf.d/oracle-instantclient.conf

然后运行ldconfig读取新配置。

将此添加到我的 Dockerfile:

# Install Oracle instantclient and oci8 extension
RUN mkdir /opt/oracle \
    && curl 'https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip' --output /opt/oracle/instantclient-basic-linux.zip \
    && curl 'https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip' --output /opt/oracle/instantclient-sdk-linux.zip \
    && unzip '/opt/oracle/instantclient-basic-linux.zip' -d /opt/oracle \
    && unzip '/opt/oracle/instantclient-sdk-linux.zip' -d /opt/oracle \
    && rm /opt/oracle/instantclient-*.zip \
    && mv /opt/oracle/instantclient_* /opt/oracle/instantclient \
    && docker-php-ext-configure oci8 --with-oci8=instantclient,/opt/oracle/instantclient \
    && docker-php-ext-install oci8 \
    && echo /opt/oracle/instantclient/ > /etc/ld.so.conf.d/oracle-insantclient.conf \
    && ldconfig

顺便说一句,libaio1 也需要安装。

我遇到了同样的问题

"php -v

PHP警告:PHP启动:无法加载动态库'oci8.so'(试过:/usr/lib/php/20190902/oci8.so(libaio.so.1:无法打开共享对象文件: 没有那个文件或目录) , /usr/lib/php/20190902/oci8.so.so (/usr/lib/php/20190902/oci8.so.so: 无法打开共享对象文件: 没有那个文件或目录)) 未知在第 0 行

我用下面的命令解决了

apt-get install libaio1

按照本教程完成安装 https://gist.github.com/milo/d4a15d67e6538bf82438babc39482b80