Connect PHP 7 to Oracle Database using packages from Oracle Linux Yum Server

March 18, 2020 | 2 minute read
Text Size 100%:

Note: This post was updated to include the latest available release of PHP as well as simplified installation intstructions for Oracle Instant Client introduced starting with 19c.


We recently added PHP 7.4 to our repos on Oracle Linux yum server. These repos include also include the PHP OCI8 extenstion to connect your PHP applications to Oracle database.

In this post I describe the steps to install PHP 7.4, PHP OCI8 and Oracle Instant Client on Oracle Linux to connect PHP to Oracle Database. For this blog post, I used a free Autonomous Database included in Oracle Cloud Free Tier.

Install Oracle Instant Client

Oracle Instant Client RPMs are available on Oracle Linux yum server also. To access them, install the oracle-release-el7 package first to setup the appropriate repositories:


$ sudo yum -y install oracle-release-el7
$ sudo yum -y install oracle-instantclient19.5-basic 

If you want to be able to use SQL*Plus (this can come in handy for some sanity checks), install the SQL*Plus RPM also:

$ sudo yum -y install oracle-instantclient19.5-sqlplus 

Create a Schema and Install the HR Sample Objects (Optional)

You can use any schema you already have in your database. I’m going to use the HR schema from the Oracle Database Sample Schemas on If you already have a schema with database objects to work with, you can skip this step.

$ yum -y install git 
$ git clone 
$ cd db-sample-schemas/human_resources 

As SYSTEM (or ADMIN, if you are using Autonomous Database), create a user PHPTEST

SQL> grant connect, resource, create view to phptest identified by <YOUR DATABASE PASSWORD>; 
SQL> alter user PHPTEST quota 5m on USERS; 

If you are using Autonomous Database like I am, change the tablespace above to DATA:

SQL> alter user phptest quota 5m on DATA; 

As the PHPTEST user, run the scripts hr_cre.sql and hr_popul.sql to create and populate the HR database objects

SQL> @hr_cre.sql
SQL> @hr_popul.sql 

Install PHP and PHP OCI8

To install PHP 7.4, make sure you have the latest oracle-php-release-el7 package installed first.

$ sudo yum install -y oracle-php-release-el7

Next, install PHP and the PHP OCI8 extenstion corresponding to the Oracle Instant Client installed earlier:

$ sudo yum -y install php php-oci8-19c 

Running the following php code snippet should verify that we can connect PHP to the database and bring back data. Make sure you replace the schema and connect string as appropriate.


Create a file emp.php based on the code above.

Run it!

$ php emp.php 

This should produce the following:

De Haan


Sergio Leunissen

Previous Post

Taming Tracepoints in the Linux Kernel

Alan Maguire | 7 min read

Next Post

Announcing the Unbreakable Enterprise Kernel Release 5 Update 3 for Oracle Linux

Simon Coter | 3 min read