4

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!

12

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

  1. Download the basic (like instantclient-basic-linux.x64-12.2.0.1.0.zip) and the sdk (instantclient-sdk-linux.x64-12.2.0.1.0.zip) 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

ldconfig

8a. Now install OCI8 by pecl

pecl install oci8

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

instantclient,/opt/oracle/instantclient

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

=PHP CONNECTION EXAMPLE=

<?php
// Create connection to Oracle, change HOST IP and SID string!
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 000.000.000.000)(PORT = 1521)))(CONNECT_DATA=(SID=XXX)))";
// Enter here your username (DBUSER) and password!
$conn = oci_connect("DBUSER", "PASSWORD",$db);
if (!$conn) {
   $m = oci_error();
   echo $m['message']. PHP_EOL;
   exit;
}
else {
   print "Oracle database connection online". PHP_EOL;
}

?>
| improve this answer | |
  • 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 '18 at 13:03
  • I tried your instruction with Ubuntu 18.04, ISPConfig 3.1 and Oracle 11. Everything works perfectly!!! – mikia Dec 18 '18 at 10:07
  • Perfect.. everything worked. – hybrid May 1 '19 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. – Daniel Steiner Oct 30 '19 at 20:28

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.