I want to share some information about my OCI8 installation to access Oracle databases.

If you got errors like "PHP Startup: Unable to load dynamic library 'oci8.so'"

or "checking Oracle Instant Client library version compatibility... configure: error: Link from libclntsh.so to /opt/oracle/instantclient/libclntsh.so.*.1 not found"

or just want to install Quick&Easy OCI8 to get a connection between your php and an Oracle database, you are at the right place!

1 Answer 1


First prerequirements are a working apache2 and php7.2 (Ubunti 18.04) environement.

  1. Download the basic (like instantclient-basic-linux.x64- and the sdk (instantclient-sdk-linux.x64- package from the Oracle Website http://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html

  2. Upload both files to your webserver, you can use WinSCP for it

  3. Unzip both files on server, in my case, you will get a new folder named "instantclient_12_2"

4a. Create destination folder

mkdir /opt/oracle

4b. Move and rename the instantclient folder

mv instantclient_12_2 /opt/oracle/instantclient

4c. Change rights on folder

chown -R root:www-data /opt/oracle

  1. Check if you have the required packages for installing OCI8

apt install php7.2-dev php-pear build-essential libaio1

  1. Create necessary soft links

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

ln -s /opt/oracle/instantclient/libocci.so.12.1 /opt/oracle/instantclient/libocci.so

7a. Add instant client to ld config files

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

7b. Update Dynamic Linker Run-Time Bindings


8a. Now install OCI8 by pecl

pecl install oci8

8b. The OCI8 installation is asking you for the right folder


9a. Add oci lib to the cli php config (console php)

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

9b. Add oci lib to the apache php config

echo "extension = oci8.so" >> /etc/php/7.2/apache2/php.ini

10a. Set environement variables for the cli version (you will need to reboot the server after)

echo "LD_LIBRARY_PATH=\"/opt/oracle/instantclient\"" >> /etc/environment

echo "ORACLE_HOME=\"/opt/oracle/instantclient\"" >> /etc/environment

10b. Set environement variables for the apache version

echo "export LD_LIBRARY_PATH=\"/opt/oracle/instantclient\"" >> /etc/apache2/envvars

echo "export ORACLE_HOME=\"/opt/oracle/instantclient\"" >> /etc/apache2/envvars

  1. Restart Apache

service apache2 restart

  1. You're done, now you can test your connection to the Oracle database


// Create connection to Oracle, change HOST IP and SID string!
// Enter here your username (DBUSER) and password!
$conn = oci_connect("DBUSER", "PASSWORD",$db);
if (!$conn) {
   $m = oci_error();
   echo $m['message']. PHP_EOL;
else {
   print "Oracle database connection online". PHP_EOL;

  • Work fine. This help me a lot. But you missed one command: echo "extension = oci8.so" >> /etc/php/7.2/fpm/php.ini
    – mikia
    Dec 17, 2018 at 13:03
  • I tried your instruction with Ubuntu 18.04, ISPConfig 3.1 and Oracle 11. Everything works perfectly!!!
    – mikia
    Dec 18, 2018 at 10:07
  • Perfect.. everything worked.
    – hybrid
    May 1, 2019 at 2:51
  • Wow. thats a ton of work just to get a PHP extension to work but it works like a charm. Got v11 running in homestead thanks to that tutorial. Oct 30, 2019 at 20:28
  • Thank you! Also works with instantclient_19_6 on php7.4. But, in this case, specify sudo pecl install oci8-2.2.0. If you've messed up a bit, and you're receiving pecl/oci8 is already installed and is the same as the released version 2.2.0, try to issue a sudo pecl uninstall oci8-2.2.0, immediately followed by the install verb. Jan 12, 2021 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.