1

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?

2 Answers2

2

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.

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
  • Thank you, you are right, actually the problem was solved by changing the place of `ENV LD_LIBRARY_PATH /opt/oracle/instantclient` to be before installing PHP extensions, but I did not pay attention that I had a different error which I solved by installing the missing packages then I edited and answered my question which obviously has a different problem than the original one. I will keep the edited version of the question because the original one has a similar one [here](https://stackoverflow.com/questions/47833041/unable-to-load-dynamic-library-oci8-so-php-7-2) – Albaraa Alshahhoud Jun 14 '22 at 18:20
2

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