Install Oracle database support in PHP CentOS 6

Howto install Oracle database support in PHP for CentOS 6 and Amazon Linux AMI.

To access an Oracle database from PHP you need to use the OCI8 extension. I will take you through the quick process of getting it up and running.

This guide assumes you already have Apache and PHP installed in your environment running on either CentOS 6 or Amazon Linux AMI. It also assumes the Oracle database you wish to connect to is on a remote host.

Step 1: Install required packages

Run the following commands from your console:

 Step 2: Download and Install Oracle instant client

You can get the Oracle Instant Client RPM’s from the Oracle website.

Oracle Instant Client 64bit Download Page

Oracle Instant Client 32bit Download Page

I’m going to be using the 64bit version of the client so I’ll need to download the following two files:

  1. oracle-instantclient11.2-basic-
  2. oracle-instantclient11.2-devel-

Once I have downloaded them from the Oracle website I can now install the instant client RPM’s using YUM:

 Step 3: Install OCI8

We are now ready to install the OCI8 extension, from your console run:

You will be prompted for the path to your Oracle libraries, since I’m building for 64bit I used the following value (type full option instantclient,<path>):

 Step 4: Configure LD and PHP.ini

From your console run:

You can restart Apache to get new php.ini values.

OCI8 Examples

Here is an example of a basic query using PHP OCI8:

 You can find more examples here



  1. Mike H   •  

    I think I love you…… This is exactly what I was looking for. It took me 2 hours to find it, but finally an easy thorough guide to connecting to a remote oracle database! You have done the community a favor my friend.

  2. Mike H   •  

    What is strange is, this matched EXACTLY what I needed to do on my staging server. I needed the same oracle versions and use a variation of CENTOS

  3. Emmanuel   •  

    echo “” >> /etc/php.ini

    Be careful that “” is in a new line and not at the end of and existing line.

  4. George   •  

    Default SELinux configuration in CentOS6 prevents loading Oracle Client libraries to httpd!

  5. Brian   •  

    An excellent concise and straight to the point guide on installing the Oracle Instant Client with PHP support on CentOS. Works a treat on CentOS 7 as well. Many thanks!

  6. Bob   •  

    Does this work with Advanced Security “Required” server configuration?

Leave a Reply to Emmanuel Cancel reply

Your email address will not be published. Required fields are marked *

− five = 0

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">