Setup ORACLE 12C / 11G PDO for PHP 7.2 / 7.x

By | July 20, 2018

Bismillahi-r-Rahmani-r-Rahim (In the name of Allah, the most Compassionate, the most Merciful)

Assalamu alaikum wa rahmatullahi wa barakatuh (May the peace, mercy, and blessings of Allah be with you)

This is the ad hoc tutorial on how to enable PHP PDO for ORACLE 12C / 11G. First, we will download and install necessary files and rpm packages. Then we will make the needed system configurations. Next we’ll install the Oracle pdo package, create the php configuration file and test the connectivity with PDO to ORACLE server.

Below content is complementary to the video tutorial above.

Download and install necessary files and packages:
1. Get your Oracle version using SQL query:

select * from product_component_version;

2. Download rpm basic and devel packages corresponding your version from
3. Copy downloaded basic and devel rpm packages to your server.

yum install -y gcc glibc glibc-common gd gd-devel wget
rpm -ivh oracle-instantclient12.2-basic-
rpm -ivh oracle-instantclient12.2-devel-
rm -f  oracle*.rpm

Make the necessary configurations:

ls /usr/include/oracle
ln -s /usr/include/oracle/$oracle_version/client64 /usr/include/oracle/$oracle_version/client
ln -s /usr/lib/oracle/$oracle_version/client64 /usr/lib/oracle/$oracle_version/client
echo "export LD_LIBRARY_PATH=/usr/lib/oracle/$oracle_version/client64/lib" > /etc/profile.d/
source /etc/profile.d/

Install the PHP Oracle pdo packages:

php -v
tar xfvz php-$php_version.tar.gz
cd php-$php_version/ext/pdo_oci
./configure --with-pdo-oci=instantclient,/usr/lib/oracle/$oracle_version/client64/lib,$oracle_version
make install
cd ~
rm -Rf php-$php_version*

Create the PHP configuration file:

echo "" > /etc/php.d/pdo_oci.ini
php -i | grep oci

Restart the necessary services:

service httpd restart && service php-fpm restart

Test the installed ORACLE PDO (additionally, see the output of phpinfo() for PDO OCI section):

php -r '$con=new PDO("oci:dbname=//;charset=utf8","c##test","test");$stmt=$con->prepare("select * from product_component_version"); $stmt->execute();$stmt->setFetchMode(PDO::FETCH_ASSOC);var_dump($stmt->fetch());'

Related resources: