How to Install Oracle Driver for PHP on Ubuntu 18.04

Oracle Database, or more commonly referred to only as Oracle, is a Relational Database Management System (RDBMS) type, which is a proprietary database from Oracle Corporation. The PHP programming language can use Oracle, but by default PHP on Ubuntu 18.04 is not yet available for Oracle driver, so you have to install it manually.

*0. Requirements*

Ubuntu 18.04 must be installed using Apache and PHP (7.2).

*1.Install Oracle Driver*

Download Oracle instantclient here. Then upload to the server.

1. 2.

Extract files that have been uploaded on the server.


1 2 unzip unzip

Create oracle folder.


1 mkdir /opt/oracle

Move and rename the instantclient folder.


1 mv instantclient_12_2 /opt/oracle/instantclient

Change folder ownership.


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

Install dependencies needed to install OCI8 (Oracle Instant Client 8).


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

Make a symbolic link.


1 2 ln -s /opt/oracle/instantclient/ /opt/oracle/instantclient/ ln -s /opt/oracle/instantclient/ /opt/oracle/instantclient/

Add an instant client to ldconfig.


1 echo /opt/oracle/instantclient > /etc/

Update Dynamic Linker Run-Time Bindings


1 ldconfig

Install oci8.


1 pecl install oci8

Showing questions


1 Please provide the path to the ORACLE_HOME directory. Use ‘instantclient,/path/to/instant/client/lib’ if you’re compiling with Oracle Instant Client [autodetect] :

Answer with


1 instantclient,/opt/oracle/instantclient

Add OCI8 to cli php config.


1 echo “extension =” >> /etc/php/7.2/cli/php.ini

Add OCI8 to Apache PHP Config.


1 echo “extension =” >> /etc/php/7.2/apache2/php.ini

Set environement variables for cli (The server must be restarted)


1 2 echo “LD_LIBRARY_PATH=\”/opt/oracle/instantclient\”” >> /etc/environment echo “ORACLE_HOME=\”/opt/oracle/instantclient\”” >> /etc/environment

Set environement variables for apache.


1 2 echo “export LD_LIBRARY_PATH=\”/opt/oracle/instantclient\”” >> /etc/apache2/envvars echo “export ORACLE_HOME=\”/opt/oracle/instantclient\”” >> /etc/apache2/envvars

Restart apache


1 systemctl restart apache2


Create info.php file.


1 echo “” > /var/www/html/info.php

Browse http://IP-SERVER/info.php, find oci8.

PHP Info – oci8

Good luck 🙂

Leave a Reply

Your email address will not be published.