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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47833041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:35:54  来源:igfitidea点击:

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

phpdockeroci8

提问by Shen

Since the update of PHP 7.1 to PHP 7.2 I can't install oci8. I have this error:

自从 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

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

PHP警告:PHP启动:无法加载动态库'oci8.so'(尝试:/usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so(libmql1.so:无法打开)共享目标文件:没有那个文件或目录),/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: 无法打开共享对象文件: No such file or directory)) in Unknown on line 0

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

I'm using Docker environment, I created a github repo for this, it works if I use the version 7.1of PHP (shenron/docker-php-fpm:7.2).

我正在使用 Docker 环境,我为此创建了一个 github 存储库,如果我使用PHP 7.1版(shenron/docker-php-fpm:7.2),它就可以工作。

I don't understand why the script try to launch this file: /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.

To my point of view there are two possibilities; or the driver is not compatible, or pecl can't today install oci8.

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

Has anyone the same problem ?

有没有人有同样的问题?

Thank you for your help.

感谢您的帮助。

回答by Jonas Osburg

/usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.so.sois only the second guess on the shared library file name. You can safely ignore that.

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

The actual problem is: (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)

实际问题是: (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.soitself depends on multiple shared libraries, you can use lddto find out which ones:

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

Those .sofiles seem to be part of a zip file in your repository. Running PHP like this LD_LIBRARY_PATH=/usr/local/instantclient_12_1/ phpworks fine inside your container. You need to move those so files to a sane location.

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

回答by user728650

For anyone stumbling upon this question, here is the proper way to handle it in linux. (I am using CentOS commands for the demo below but Ubnutu shouldn't be any different)

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

step 1: get oracle libs

第 1 步:获取 oracle 库

EDIT: Thanks to Christopher Jones for the comment, you can find the direct rpm links at https://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/

编辑:感谢 Christopher Jones 的评论,您可以在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 

step 2: install

第 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 

step 3: configure (make the path of the oracle libs to be discoverable)

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

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

test

测试

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

回答by Greg

If running ldd /usr/local/lib/php/extensions/no-debug-non-zts-20170718/oci8.sogives you something like this, with missing files:

如果运行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

You can add the folder to your ldconfig like this (other readers - your path may vary):

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

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

Then run ldconfigto read the new config.

然后运行ldconfig以读取新配置。

回答by Tomme

Added this to my Dockerfile:

将此添加到我的 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 also needs to be installed btw.

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