Introduction

NOTE: See my updated Installing OCI8 as a Shared Extension on RHEL or CentOS article which updates this one.

In response to my extremely (thousands of hits) popular article Installing OCI8 on RHEL, I decided to add this article since I find those instructions have become somewhat out of date, and also it is recommended to use PHP 7.2 with any web application that you are currently supporting. PHP 7.2 provides significant performance improvements over PHP 7.0, so if you are using PHP 7.0, I highly recommend updating to PHP 7.2.

Stopping Apache

You’ll need to stop Apache (web server) using the following command. In any Linux commands I show in this article, it presumes you aren’t logged in as the root user, so you will need to use sudo to issue privileged commands.

sudo service httpd stop

Add EPEL & Remi Repositories

You’ll need to install the EPEL & Remi repositories as follows:

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm

Set Config Manager for PHP 7.2

You’ll need to get the yum-utils to use the yum-config-manager to set the default repository using the following commands:

sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72

The above enables the Remi PHP 7.2 repository.

Installing PHP 7.2

If you already have PHP 5.x or PHP 7.0 installed, you will need to figure out how to remove it. I used this command to remove php70u from my system(s):

sudo yum remove php70u-common.x86_64

You can then check to see if you still have php installed with this command:

sudo yum list installed |grep php

You shouldn’t see anything related to php installed, otherwise uninstall the package.

Then you can install PHP 7.2; in my scenario, I normally develop Symfony applications that use PHP in Apache. In my case I would use the following command to install:

sudo yum install php php-pecl-mcrypt php-cli php-gd php-curl php-mysqlnd php-ldap php-zip php-fileinfo php-xml php-intl php-mbstring php-opcache php-process systemtap-sdt-devel php-pear php-json php-devel php-common php-bcmath php-pdo

This installs all the packages I need.

Installing OCI8

This is the part that could get tricky. You should be able to issue the following at this point:

sudo yum install php-oci8

Then you’ll need to edit the php.ini file as follows:

sudo vi /etc/php.ini

Which is the typical location of the php.ini file. In Symfony, look at the “View phpinof()” link, and then look for the “Loaded Configuration File”, which shows the file you need to edit. Then at the bottom of this file add this line:

extension=oci8.so

Then in vi, issue the command “:wq!” to save the file and quit. Then to check if php is installed correct, issue this command:

php -v

If you see errors like unable to load dynamic link library oci8.so, then you probably need to reinstall Oracle Instant Client or you haven’t installed it.

Installing Oracle Instant Client

You need to download for your Linux client, for example the following 2 files:

oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm

Make sure they are in your home directory, then install with the following commands:

sudo yum install oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
sudo yum install oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm

sudo sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig

Then issue the following command to verify PHP is installed correctly:

php -v

You should see no error and version PHP 7.2 shown.

Verifying OCI8 & PHP 7.2 on Web Server

You’ll need to restart your Apache web server:

sudo service httpd restart

Then in Symfony look at the “View phpinfo()” link. Or create your own using this code:

<? phpinfo(); ?>

Then search on the page for the string “oci8”, you should see something like the following image:

OCI8 Shown in PHPInfo