在Dockerfile中安装并启用php:8.1-fpm的OCI 8扩展

g6baxovj  于 2023-08-02  发布在  PHP
关注(0)|答案(2)|浏览(179)

我正在尝试安装和启用OCI 8在dockerfile为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

字符串

完整dockerfilehere

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


当我检查退出扩展使用RUN php -m后刚刚安装和警告,我发现没有安装oci 8。
那该如何修复呢?

h9vpoimq

h9vpoimq1#

在安装PHP扩展之前,请将系统库搜索路径设置为包含Instant Client库。最好的方法是按照Instant Client安装说明中的建议使用ldconfig。在您的情况下,它将是:

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

字符串
这也意味着您可以从步骤RUN LD_LIBRARY_PATH=/usr/local/instantclient_21_6/ php中删除LD_LIBRARY_PATH。事实上,这一整行都没有用。
您可能会发现Docker for Oracle Database Applications in Node.js and Python中的一些Instant Client提示很有用。

8yoxcaq7

8yoxcaq72#

起初我以为这是路径问题,但真实的的错误在警告消息的一部分中很清楚:
第一个月
这个命令还显示了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


ERROR: failed to solve: process "/bin/sh -c echo 'instantclient,/opt/oracle/instantclient/' | pecl install oci8" did not complete successfully: exit code: 1
在编译输出中仔细搜索了更多关于错误的信息之后,我发现了这一行中的问题:#error Use PHP OCI8 3.2 for your version of PHP
我不知道为什么它以前工作,我认为这个特定的版本要求是最近增加的,所以我简单地更改了命令来安装OCI8的特定版本

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

相关问题