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

9

8

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

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

I'm using Docker environment, I created a github repo for this, it works if I use the version 7.1 of PHP (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.

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

Has anyone the same problem ?

Thank you for your help.

Cannibal answered 15/12, 2017 at 13:7 Comment(1)
This worked for me #47771632Andante
N
15

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

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)

oci8.so itself depends on multiple shared libraries, you can use ldd to find out which ones:

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 .so files seem to be part of a zip file in your repository. Running PHP like this LD_LIBRARY_PATH=/usr/local/instantclient_12_1/ php works fine inside your container. You need to move those so files to a sane location.

Newlywed answered 15/12, 2017 at 13:31 Comment(2)
Thank you very much for your help ! I updated my Docker file to fix the problem: ENV LD_LIBRARY_PATH /usr/local/instantclient_12_1/Cannibal
It's generally better to use ldconfig to set the library path. This is shown on the Instant Client install page. This avoids issues with how and where to set LD_LIBRARY_PATH, and avoids issues with that variable being reset in some environments.Asiaasian
P
7

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)

step 1: get oracle libs

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/

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

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)

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)...
Printmaking answered 27/11, 2018 at 16:27 Comment(1)
The Instant Client RPMs are at yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/… so you can run wget http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient18.3-basic-18.3.0.0.0-2.x86_64.rpm etcAsiaasian
I
3

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

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):

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

Then run ldconfig to read the new config.

Inellineloquent answered 14/11, 2019 at 15:28 Comment(1)
That did the trick for me in the instance that root could load the extension, but a non-root user could not. Thank you!Bistort
R
2

Added this to my 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.

Reflation answered 27/4, 2020 at 16:37 Comment(1)
My blog post Docker for Oracle Database Applications in Node.js and Python shows some other ways to install Instant Client for languages like PHP.Asiaasian
S
1

I had the same problem

"php -v

PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20190902/oci8.so (libaio.so.1: cannot open shared object file: No such file or directory) , /usr/lib/php/20190902/oci8.so.so (/usr/lib/php/20190902/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0"

I solved it with the following command

apt-get install libaio1

Follow this tutorial for complete installation https://gist.github.com/milo/d4a15d67e6538bf82438babc39482b80

Sedimentology answered 24/9, 2021 at 2:49 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Decomposer
F
0

I had the problem with php8: I created the file etc/apache/envvars In that, I wrote: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib export ORACLE_HOME=/usr/lib/oracle/11.2/client64

Then, it`s important, how the apache is restared (a systemctl restart did not work in my case). I did: apache2ctl stop apache2ctl start

...and everything was fine.

Fairlead answered 24/10, 2022 at 10:18 Comment(0)
P
0

I ran into this problem with php8.1 on ubuntu and I wanted to share how I solved it since I never found the solution in any guides on the web. My system has multiple versions of php on it and even though I have my server set up to use php8.1, since 8.2 was on my system the build process for oci8 was happening with php8.2.

The only way I discovered this was reading the error message that php -i was giving:

PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20210902/oci8.so (/usr/lib/php/20210902/oci8.so: cannot open shared object file: No such file or directory), /usr/lib/php/20210902/oci8.so.so (/usr/lib/php/20210902/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

and comparing that with what I was seeing at the end of the oci8 build.

Build process completed successfully Installing '/usr/lib/php/20220829/oci8.so' install ok: channel://pecl.php.net/oci8-3.3.0 configuration option "php_ini" is not set to php.ini location You should add "extension=oci8.so" to php.ini

Clearly php was looking in a different directory than where oci8 was being created. At first I tired to symlink the file created by the build into the directory where php was looking but that returned this error.

PHP Warning: PHP Startup: oci8: Unable to initialize module Module compiled with module API=20220829 PHP compiled with module API=20210902 These options need to match

That's when I realized the version of php I was using was influencing the final build file. After adjusting my commands to specify php8.1 and the oci8 version compatible with 8.1 everything worked as it should.

First install the right php-dev version

sudo apt-get install php8.1-dev php-pear build-essential libaio1 -y

Then install the right oci8 version for php8.1. Versions are listed here.

sudo pecl channel-update pecl.php.net
sudo pecl -d php_suffix=8.1 install pecl install oci8-3.2.1

Hopefully this helps anyone struggling with a similar error.

Pearse answered 14/9, 2023 at 20:16 Comment(0)
O
0

In my case, same error with php v8.2.

Using Debian Linux with php v8.2 and Oracle instantclient v.21.8.0, I solved installing libaio1 library, so:

sudo apt-get install libaio1

If you build docker image throw Dockerfile, I rewrote a section of my script like this:

# Install Oracle oci8 php ext for Instant Client
RUN apt-get update && apt-get install -y libaio1 \
    && mkdir -p /opt/oracle \
    && cd /opt/oracle \
    && wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip \
    && wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip \
    && wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-sqlplus-linux.x64-21.8.0.0.0dbru.zip \
    # && export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_8 \
    && unzip instantclient-basic-linux.x64-21.8.0.0.0dbru.zip \
    && unzip instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip \
    && unzip instantclient-sqlplus-linux.x64-21.8.0.0.0dbru.zip \
    && pecl channel-update pecl.php.net \
    && echo "instantclient,/opt/oracle/instantclient_21_8" | pecl install oci8 \
    && echo /opt/oracle/instantclient_21_8 > /etc/ld.so.conf.d/oracle-instantclient.conf \
    && ldconfig \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

and then:

docker compose up --build
# or
# docker-compose up --build if using previous version of docker composer..
Outrange answered 24/7 at 10:15 Comment(0)
E
0

I had a similar problem trying using php7.3 with oci8 on my ubuntu 24.04. After many hours of searching on forums and googling, the answer from Jonas Osburg above helped me. It turned out my system wasn't find libaio.so.1. So i ran the following commands:

sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so /usr/lib/x86_64-linux-gnu/libaio.so.1

and

sudo ldconfig

That solved my problem.

Efface answered 25/7 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.