Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ingeJulianLasso/9d50cfd8c28618984d3cccd616ca8ff2 to your computer and use it in GitHub Desktop.
Save ingeJulianLasso/9d50cfd8c28618984d3cccd616ca8ff2 to your computer and use it in GitHub Desktop.
How to install OCI8 on Ubuntu 16.04 or 18.04 and PHP 7.3 (Instant Client 12.2)

How to install OCI8 on Ubuntu 18.04 and PHP 7.3

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

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

Source: https://gist.github.com/hewerthomn/81eea2935051eb2500941a9309bca703#file-install_oci8_ubuntu_16-04_php7-1-md

Source: https://gist.github.com/Yukibashiri/cebaeaccbe531665a5704b1b34a3498e

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.2.0.1.0.zip and instantclient-sdk-linux.x64-12.2.0.1.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.

sudo mkdir /opt/oracle

Step 3

Now we need to extract the files.

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

Step 4

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

sudo ln -s /opt/oracle/instantclient_12_2/libclntsh.so.12.1 /opt/oracle/instantclient_12_2/libclntsh.so
sudo ln -s /opt/oracle/instantclient_12_2/libocci.so.12.1 /opt/oracle/instantclient_12_2/libocci.so

Step 5

Add the folder to our ldconfig.

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

Step 6

Update the Dynamic Linker Run-Time Bindings

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

sudo apt-get install php7.3-dev php-pear build-essential libaio1

Step 2

Once installed, we need to get the OCI8 file. But, before that we need to update PECL channel.

sudo pecl channel-update pecl.php.net

Then.

sudo pecl install oci8

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

instantclient,/opt/oracle/instantclient_12_2

Step 3

We need to tell PHP to load the OCI8 extension.

sudo sudo echo "extension=oci8.so" >> /etc/php/7.3/mods-available/oci8.ini
sudo sudo phpenmod oci8

We also need to add on apache those environment variables.

sudo echo "export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2" >> /etc/apache2/envvars
sudo echo "export ORACLE_HOME=/opt/oracle/instantclient_12_2" >> /etc/apache2/envvars
sudo echo "LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH" >> /etc/environment

Step 4

Restart the Apache server

sudo /etc/init.d/apache2 restart

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

Important note

My computer to develop works with Ubuntu Desktop 18.04 but the server is in Ubuntu Server 16.04, so what I do in my workstation I must replicate on the server and the steps above work perfectly in Ubuntu Server 16.04.

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