Install Oracle Instant Client

Download Oracle Instant Client packages

First, select right client for your OS here(http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html),
Instant Client for Linux x86-64(http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html) in my case for my 64-bit Ubuntu 14.04.
Then Accept License Agreement and download basic & devel rpm packages for your Oracle version.
Our Oracle DB version is 11g r2, so I need to download:


Install the instant client

Convert .rpm to Debian software package (.deb) using alien:

sudo apt-get install alien
sudo alien -d oracle-instantclient11.2-basic-
sudo alien -d oracle-instantclient11.2-devel-

This will output oracle-instantclient11.2-basic- & oracle-instantclient11.2-devel- which can be installed via Ubuntu’s dpkg command:

sudo dpkg -i oracle-instantclient11.2-basic_11.
sudo dpkg -i oracle-instantclient11.2-devel_11.

After successful installation, client library with be installed in /usr/share/oracle/11.2/client64, and developer header files with be in /usr/include/oracle/11.2/client64.

Export ORACLE_HOME environment variable

We need these environment variable to compile PDO_OCI & OCI8 extensions:

export ORACLE_HOME=/usr/lib/oracle/11.2/client64
sudo ldconfig

Download, compile and install PHP PDO_OCI and OCI8 extensions

Download PHP source

Assuming that you already have PHP installed on your system, you just need to compile and install the extensions separately.
At first, check your current PHP version by command php -v and download corresponding PHP source archive from http://php.net/downloads.php. In my case, I downloaded PHP-5.5.9 from http://php.net/get/php-5.5.9.tar.bz2/from/a/mirror, & uncompressed it using command:

wget http://cn2.php.net/get/php-5.5.9.tar.bz2/from/this/mirror php-5.5.9.tar.bz2

tar xjf php-5.5.9.tar.bz2

Then prepare pdo_oci extension for compiling using:

cd php-5.5.9/ext/pdo_oci

This will prepare configure script for you.
Note: You need php5-dev package to use phpize command. If you don’t have it on your system, just install by sudo apt-get install php5-dev
Next, proceed with configure to create Makefile:


You may get an error yells that configure: error: Cannot find php_pdo_driver.h. This is because the configure script tries to look for php include files in /usr/include/php that has been changed to /usr/include/php5 for latest PHP versions. The quick trick here is to create a soft link for legacy path:

sudo ln -s /usr/include/php5/ /usr/include/php

and run the ./configure script again. It should succeed now. Proceed with the compilation:


It might scream another error similar to ***php-5.5.9/ext/pdo_oci/php_pdo_oci_int.h:21:17: fatal error: oci.h: No such file or directory. To bypass this, we need another trick here:

Edit Makefile file:

vim Makefile

Find the line start with EXTRA_INCLUDES = and add path to installed Oracle Instant Client header files (/usr/include/oracle/11.2/client64) to it, if this line does NOT exist, just add it near the beginning of the file. Final result should be:

EXTRA_INCLUDES = -I/usr/include/oracle/11.2/client64

Then run make again, the compilation should be complete now.
Finally, install the compiled extension to the system:

sudo make install

This will copy pdo_oci.so file to /usr/lib/php5/yyyyMMdd/pdo_oci.so

扩展编辑安装完毕之后,需要在/etc/php5/中启用PDO_OCI扩展,需要新建两个配置文件 /etc/php5/cli/conf.d/pdo_oci.ini 和 /etc/php5/fpm/conf.d/pdo_oci.ini,内容都是:


echo extension=pdo_oci.so | sudo tee -a /etc/php5/cli/conf.d/pdo_oci.ini
echo extension=pdo_oci.so | sudo tee -a /etc/php5/fpm/conf.d/pdo_oci.ini

SQLSTATE[HY000]: OCIEnvNlsCreate: Check the character set is valid and that PHP has access to Oracle libraries and NLS data…


sudo vim /etc/php5/fpm/pool.d/www.conf


env[LD_LIBRARY_PATH] = /usr/lib/oracle/11.2/client64/lib
env[ORACLE_HOME] = /usr/lib/oracle/11.2/client64/lib


sudo service php5-fpm restart

Install OCI8 and other extensions can be done easily following the same steps, with the tricks mentioned above.


Leave a Reply

Your email address will not be published.