Skip to content

Instantly share code, notes, and snippets.

@hewerthomn
Created February 22, 2017 14:45
Show Gist options
  • Star 55 You must be signed in to star a gist
  • Fork 27 You must be signed in to fork a gist
  • Save hewerthomn/81eea2935051eb2500941a9309bca703 to your computer and use it in GitHub Desktop.
Save hewerthomn/81eea2935051eb2500941a9309bca703 to your computer and use it in GitHub Desktop.
How to install OCI8 on Ubuntu 16.04 and PHP 7.1

How to install OCI8 on Ubuntu 16.04 and PHP 7.1

Source: http://www.syahzul.com/2016/04/06/how-to-install-oci8-on-ubuntu-14-04-and-php-5-6/

Install Oracle Instant Client and SDK

Step 1

Download the Oracle Instant Client and SDK from Oracle website. (Need to login in Oracle page)

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Files: instantclient-basic-linux.x64-12.1.0.2.0.zip and instantclient-sdk-linux.x64-12.1.0.2.0.zip.

Step 2

Create a new folder to store Oracle Instant Client zip files on your server.

Upload the Instant Clients files inside this folder.

mkdir /opt/oracle

Step 3

Now we need to extract the files.

cd /opt/oracle
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip

Step 4

Next, we need to create a symlink to Instant Client files.

ln -s /opt/oracle/instantclient_12_1/libclntsh.so.12.1 /opt/oracle/instantclient_12_1/libclntsh.so
ln -s /opt/oracle/instantclient_12_1/libocci.so.12.1 /opt/oracle/instantclient_12_1/libocci.so

Step 5

Add the folder to our ldconfig.

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

Step 6

Update the Dynamic Linker Run-Time Bindings

ldconfig

Done. Now we can proceed to the next part.

Install Additional Packages

To install the OCI8 extension, we need to install some additional package on our server.

Step 1

Run these command:

apt-get install php-dev php-pear build-essential libaio1

Step 2

Once installed, we need to get the OCI8 file.

pecl install oci8

When you are prompted for the Instant Client location, enter the following:

instantclient,/opt/oracle/instantclient_12_1

Step 3

We need to tell PHP to load the OCI8 extension.

echo "extension = oci8.so" >> /etc/php/7.1/fpm/php.ini
echo "extension = oci8.so" >> /etc/php/7.1/cli/php.ini

Step 4

Check if the extension is enabled.

php -m | grep 'oci8'

If returns oci8, its works!

Step 5

Restart the PHP-FPM

service php7.1-fpm restart

Now you can connect to Oracle DBMS from your PHP applications.

@Navisho
Copy link

Navisho commented Dec 16, 2017

I had the same problem and did not find anything for a full day, until I found .... https://forum.remirepo.net/viewtopic.php?pid=9291#p9291
this is what worked for me:

systemctl edit apache2
inside we add these two lines

[Service]
Environment = LD_LIBRARY_PATH = / opt / oracle / instantclient

save and restart the apache service

service apache2 restart

and that´s it.

I have ubuntu server 17.10, orale client 12.1.0.2.0 oci8 ver. 2.1.3
I hope it works for u

@Hamfri
Copy link

Hamfri commented Jan 2, 2018

I had the same problem on Ubuntu 16.04 and this is how i resolved it.

  1. Make sure you add this line extension = oci8.so to /etc/php/7.1/apache2/php.ini to make apache aware of oci8
  2. Add the following lines to /etc/apache2/envvars
    export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
    export ORACLE_HOME=/opt/oracle/instantclient_12_2
  3. Finally restart apache2 using the command /etc/init.d/apache2 restart

@paulovitorbal
Copy link

Thank you!

@nwaweru
Copy link

nwaweru commented May 16, 2018

Hi,

Any help with the below error will be much appreciated:

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

@cbj4074
Copy link

cbj4074 commented May 17, 2018

@nwaweru Where are you seeing that message? In the terminal, when you execute php? Or when you attempt to start the webserver? Also, which OS are you using?

If you're seeing that error in the terminal, then you need to add the Instant Client path to the environment. On Ubuntu 18.04 LTS, for example:

echo 'LD_LIBRARY_PATH="/opt/oracle/instantclient_12_2"' >> /etc/environment

You should then log out of the terminal session and then back in, and the error should disappear.

If you're seeing this error when you start the apache2 daemon, then you need to add the LD_LIBRARY_PATH value to your Apache environment, e.g.:

echo 'export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2' >> /etc/apache2/envvars

And then restart the Apache service.

For whatever reason, none of this was needed on Ubuntu 16.04 LTS, but it appears to be required in Ubuntu 18.04 LTS.

Unfortunately, I can't figure out how to apply the same solution to PHP-FPM running via NGINX. I've tried adding

env['LD_LIBRARY_PATH'] = /opt/oracle/instantclient_12_2

to the effective FPM pool configuration, and while the Environment section of phpinfo()'s output reflects the above value, the OCI8 extension simply does not load. I don't see any errors in relation to libmql1.so in the FPM log, either, even with verbosity set to debug. Really frustrating!!!

@lucassmacedo
Copy link

Hello guys, for any has this problem
"PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20170718/oci8.so (libmql1.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/oci8.so.so (/usr/lib/php/20170718/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0"

I solved adding the following to /etc/environment:
LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH

@NenadGajic
Copy link

I also had the same PHP Warning as above and I solved it by following this tutorial:

https://medium.com/@kabeza/setup-oracle-instant-client-with-apache-and-php-7-on-ubuntu-server-17-04-66cea2297d6f

@flik
Copy link

flik commented Nov 9, 2018

php -m | grep 'oci8'
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 (libmql1.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_oci.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_oci.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_oci.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_oci.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_oci.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
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 (libmql1.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

@heinhtet123
Copy link

hi,
i am getting the error below. how to resolve it?
Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in /app/src/public/oci8.php on line 3

Fatal error: ORA-12154: TNS:could not resolve the connect identifier specified in /app/src/public/oci8.php on line 7

@pepo-ec
Copy link

pepo-ec commented Jan 17, 2019

I had:
php -m | grep 'oci8'
PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20180731/oci8.so (libmql1.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/oci8.so.so (/usr/lib/php/20180731/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Then I use:
cat /etc/ld.so.conf.d/oracle-instantclient.conf
/opt/oracle/instantclient_18_3

sudo ldconfig -f /etc/ld.so.conf -C /etc/ld.so.cache

And that's all

@ZiTAL
Copy link

ZiTAL commented Feb 12, 2019

solved with:

echo "/opt/oracle-instantclient-12-2" >> /etc/ld.so.conf.d/x86_64-linux-gnu.conf
ldconfig

and restart the php-fpm service

@aenal-abie
Copy link

solved with:

echo "/opt/oracle-instantclient-12-2" >> /etc/ld.so.conf.d/x86_64-linux-gnu.conf
ldconfig

and restart the php-fpm service

Thank you

@ambevgabriel
Copy link

I had the same problem on Ubuntu 16.04 and this is how i resolved it.

  1. Make sure you add this line extension = oci8.so to /etc/php/7.1/apache2/php.ini to make apache aware of oci8
  2. Add the following lines to /etc/apache2/envvars
    export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
    export ORACLE_HOME=/opt/oracle/instantclient_12_2
  3. Finally restart apache2 using the command /etc/init.d/apache2 restart

You Save my life Thankssssss

@luiscordero29
Copy link

Step 5

for debian 10

root@vostro:/etc/ld.so.conf.d# ls -l
total 16
-rw-r--r-- 1 root root 38 Sep 6 18:48 fakeroot-x86_64-linux-gnu.conf
-rw-r--r-- 1 root root 44 Jul 29 2019 libc.conf
-rw-r--r-- 1 root root 31 Jan 31 15:33 oracle-instantclient.conf
-rw-r--r-- 1 root root 100 Jan 10 19:21 x86_64-linux-gnu.conf
root@vostro:/etc/ld.so.conf.d# cat oracle-instantclient.conf
/opt/oracle/instantclient_12_2
root@vostro:/etc/ld.so.conf.d#

@travnewmatic
Copy link

echo /opt/oracle/instantclient_12_1 > /etc/ld.so.conf.d/oracle-instantclient
is wrong
it should be
echo /opt/oracle/instantclient_12_1 > /etc/ld.so.conf.d/oracle-instantclient.conf

@clcneogeek325
Copy link

Please check have just one version php on your server I have had because I had two versions php

@Zaidzularsya
Copy link

Zaidzularsya commented Jun 12, 2021

i had same problem. i have try all solution but nothing was work for me.

┌──(zaidsource㉿Zaid-Desktop)-[~]
└─$ php -m | grep oci8
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

┌──(zaidsource㉿Zaid-Desktop)-[~]
└─$ ls /usr/lib/php/20190902/
build        dom.so   fileinfo.so  iconv.so  opcache.so  posix.so     simplexml.so  sysvsem.so    xmlreader.so  xsl.so
calendar.so  exif.so  ftp.so       json.so   pdo.so      readline.so  sockets.so    sysvshm.so    xml.so
ctype.so     ffi.so   gettext.so   oci8.so   phar.so     shmop.so     sysvmsg.so    tokenizer.so  xmlwriter.so

@JackelynOliveira
Copy link

The instructions above helped me a lot. I was able to get a PHP 7 application running with this Dockerfile:

FROM php:7.2.10-apache

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update

COPY instantclient-basic-linux.x64-12.2.0.1.0 /opt/oracle/instantclient/
COPY instantclient-sdk-linux.x64-12.1.0.2.0 /opt/oracle/instantclient/

RUN ln -s /opt/oracle/instantclient/libclntsh.so.12.1 /opt/oracle/instantclient/libclntsh.so

RUN echo '/opt/oracle/instantclient' > /etc/ld.so.conf.d/oracle-instantclient.conf \
    && ldconfig

RUN apt-get install build-essential libaio1 -y
    
RUN echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8-2.2.0 \
       && echo "extension=oci8.so" > /usr/local/etc/php/conf.d/php-oci8.ini

In my case, I also had to install mysql extension because of the application's requirements. So you can ignore the first RUN instruction.

@arvindwill
Copy link

# pecl install oci8
pecl/oci8 requires PHP (version >= 8.1.0), installed version is 7.0.33-0ubuntu0.16.04.16
No valid packages found
install failed

For the above failure use below command.

pecl install oci8-2.2.0

@1dajobs
Copy link

1dajobs commented Jul 15, 2023

When i ran the procedure this was my error :
PHP Warning: PHP Startup: Unable to load dynamic library 'oci8_19' (tried: /usr/lib/php/20210902/oci8_19 (/usr/lib/php/20210902/oci8_19: cannot open shared object file: No such file or directory), /usr/lib/php/20210902/oci8_19.so (/usr/lib/php/20210902/oci8_19.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20210902/oci8.so (libclntshcore.so.19.1: 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
PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20210902/oci8.so (libclntshcore.so.19.1: 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

@icanitam
Copy link

I had: php -m | grep 'oci8' PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/lib/php/20180731/oci8.so (libmql1.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/oci8.so.so (/usr/lib/php/20180731/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Then I use: cat /etc/ld.so.conf.d/oracle-instantclient.conf /opt/oracle/instantclient_18_3

sudo ldconfig -f /etc/ld.so.conf -C /etc/ld.so.cache

And that's all

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment