在Dockerfile中安装并启用PHP的OCI8扩展:8.1-fpm

发布于 2025-02-06 15:50:16 字数 2098 浏览 2 评论 0 原文

我正在尝试在dockerfile中安装和启用OCI8的php:8.1-fpm 图像到..

这是我的dockerfile的一部分:

RUN mkdir /opt/oracle
# Install Oracle Instantclient
RUN wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \
&& wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \
&& wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \
&& unzip instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle \
&& unzip instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle \
&& unzip instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle \
&& rm -rf *.zip \
&& mv /opt/oracle/instantclient_21_6 /opt/oracle/instantclient

#add oracle instantclient path to environment
ENV LD_LIBRARY_PATH /opt/oracle/instantclient/
RUN ldconfig

# Install Oracle extensions
RUN docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/opt/oracle/instantclient,21.1 \
&& echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8 \
&& docker-php-ext-install \
        pdo_oci \
&& docker-php-ext-enable \
        oci8

完整的dockerfile

这里代码> docker -compose build :成功地使用此警告构建:

Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_oci.so (Error loading shared library libaio.so.1: No such file or directory (needed by /usr/local/instantclient_21_6/libclntsh.so.21.1)), /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_oci.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_oci.so.so: No such file or directory)) in Unknown on line 0

当我使用运行php -m 在安装后使用警告后,我发现了,我发现了这一点OCI8未安装。

那么如何修复呢?

I'm trying to install and enable OCI8 in dockerfile for php:8.1-fpm
image to ..

This is a part of my Dockerfile:

RUN mkdir /opt/oracle
# Install Oracle Instantclient
RUN wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip \
&& wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip \
&& wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip \
&& unzip instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle \
&& unzip instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle \
&& unzip instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle \
&& rm -rf *.zip \
&& mv /opt/oracle/instantclient_21_6 /opt/oracle/instantclient

#add oracle instantclient path to environment
ENV LD_LIBRARY_PATH /opt/oracle/instantclient/
RUN ldconfig

# Install Oracle extensions
RUN docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/opt/oracle/instantclient,21.1 \
&& echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8 \
&& docker-php-ext-install \
        pdo_oci \
&& docker-php-ext-enable \
        oci8

full dockerfile is here

docker-compose build: Successfully built with this warning:

Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_oci.so (Error loading shared library libaio.so.1: No such file or directory (needed by /usr/local/instantclient_21_6/libclntsh.so.21.1)), /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_oci.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_oci.so.so: No such file or directory)) in Unknown on line 0

when I checked for the exited extensions using RUN php -m just after the installation is done with warnings, I have found out that oci8 is not installed.

So how to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩心不撩汉 2025-02-13 15:50:16

起初,我认为这是一个路径问题,但是在警告消息的一部分中很明显的真正错误:

错误加载共享库libaio.so.1:no这样的文件或目录

此命令显示 oci8.so 的缺失库是什么是什么:

RUN ldd /usr/local/lib/php/extensions/no-debug-non-zts-20210902/oci8.so

输出:

        linux-vdso.so.1 (0x00007ffe4017a000)
        libclntsh.so.21.1 => /opt/oracle/instantclient/libclntsh.so.21.1 (0x00007fd247169000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd246fa0000)
        libnnz21.so => /opt/oracle/instantclient/libnnz21.so (0x00007fd24692b000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd246925000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd2467e1000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd2467bf000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd2467b2000)
        libaio.so.1 => not found
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fd246798000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd24b57f000)
        libclntshcore.so.21.1 => /opt/oracle/instantclient/libclntshcore.so.21.1 (0x00007fd2461e8000)
        libaio.so.1 => not found

输出所说: libaio.so.1 缺少。

我通过安装这些软件包解决了它:

RUN apt-get install libaio1 libaio-dev

编辑:

我最近尝试重建dockerfile的相同版本,并且我在执行此命令时特别是安装了OCI8的错误:

echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8

错误:错误:失败:无法解决:无法解决。 :process“/bin/sh -c echo'instantClient,/opt/oracle/intermantclient/'| pecl install oci8”未能成功完成:退出代码:1

在仔细搜索构建的输出之后,有关错误的更多信息,我在此行中发现了问题:
#Error使用PHP OCI8 3.2用于您的PHP版本

我不知道为什么它以前工作了,我认为最近添加了此特定版本的要求,因此我更改了命令以安装该特定版本OCI8

echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8-3.2.1

At first I thought it was a path issue, but the real error which was clear in part of the warning message:

Error loading shared library libaio.so.1: No such file or directory

also this command shows what is exactly the missing libraries for oci8.so:

RUN ldd /usr/local/lib/php/extensions/no-debug-non-zts-20210902/oci8.so

output:

        linux-vdso.so.1 (0x00007ffe4017a000)
        libclntsh.so.21.1 => /opt/oracle/instantclient/libclntsh.so.21.1 (0x00007fd247169000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd246fa0000)
        libnnz21.so => /opt/oracle/instantclient/libnnz21.so (0x00007fd24692b000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd246925000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd2467e1000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd2467bf000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd2467b2000)
        libaio.so.1 => not found
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fd246798000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd24b57f000)
        libclntshcore.so.21.1 => /opt/oracle/instantclient/libclntshcore.so.21.1 (0x00007fd2461e8000)
        libaio.so.1 => not found

as the output says: libaio.so.1 is missing.

I solved it by Installing these packages:

RUN apt-get install libaio1 libaio-dev

Edit:

I tried to rebuild the same version of the Dockerfile lately and I got an error installing OCI8, specifically while executing this command:

echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8

ERROR: failed to solve: process "/bin/sh -c echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8" did not complete successfully: exit code: 1

after a careful search in the output of the build for more info about the error I found the problem in this line:
#error Use PHP OCI8 3.2 for your version of PHP

I don't know why it was working before, I think this specific version requirement was added lately, So simply I changed the command to install that specific version of OCI8

echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8-3.2.1
初吻给了烟 2025-02-13 15:50:16

在安装PHP扩展程序之前,设置系统库搜索路径以包含即时客户端库。最好的方法是按照 ldconfig #ic_x64_inst“ rel =“ nofollow noreferrer”>即时客户端安装指令。在您的情况下,这将是:

RUN echo /opt/oracle/instantclient_21_6/ > /etc/ld.so.conf.d/oic.conf && \
    ldconfig

这也意味着您可以从步骤运行ld_library_path =/usr/usr/local/instantclient_21_6/php 中删除ld_library_path。实际上,整行没有用。

您可能会在 docker for node.js和python中的oracle数据库应用程序有用。

Set the system library search path to contain the Instant Client libraries before installing the PHP extensions. The best way is to use ldconfig as recommended in the Instant Client installation instructions. In your case it would be:

RUN echo /opt/oracle/instantclient_21_6/ > /etc/ld.so.conf.d/oic.conf && \
    ldconfig

This would also mean you can remove LD_LIBRARY_PATH from the step RUN LD_LIBRARY_PATH=/usr/local/instantclient_21_6/ php. In fact, that whole line isn't useful.

You may find some of the Instant Client tips in Docker for Oracle Database Applications in Node.js and Python useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文