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.
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.
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:
Then in vi, issue the command “:wq!” to save the file and quit. Then to check if php is installed correct, issue this command:
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:
Make sure they are in your home directory, then install with the following commands:
sudo yum install oracle-instantclient12.2-basic-126.96.36.199.0-1.x86_64.rpm sudo yum install oracle-instantclient12.2-devel-188.8.131.52.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:
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:
Thank you very much. it is working perfectly.
Glad you got it working!
Thank you so much! I was trying to create a new updated server and I was having a horrendous time getting the oci8 to be recognized. With your information, it is FINALLY there. (RHEL 7, Client 184.108.40.206, php 7.3.5)
Glad you got the install working! You might want to “Like” my post or rate it. Thank you!
I followed all the steps but the output of php -v looks like below. Any suggestions
[root@SPLAWSINTGUI01 admgtoks]# php -v
PHP Warning: Module ‘oci8’ already loaded in Unknown on line 0
PHP 5.4.16 (cli) (built: Oct 29 2019 09:56:22)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies
My guess is that you didn’t even search on Google for this correct?
If you did, you would have found this:
Basically, you’ve already specified it somewhere else in a config file somewhere. Welcome to the IT world!
Hello, i hope you can help
i still got the error:
PHP Warning: PHP Startup: Unable to load dynamic library ‘oci8.so’ (tried: /usr/lib64/php/modules/oci8.so (libclntsh.so.18.1: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/oci8.so.so (/usr/lib64/php/modules/oci8.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘oci8’ (tried: /usr/lib64/php/modules/oci8 (/usr/lib64/php/modules/oci8: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/oci8.so (libclntsh.so.18.1: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘pdo_oci’ (tried: /usr/lib64/php/modules/pdo_oci (/usr/lib64/php/modules/pdo_oci: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/pdo_oci.so (libclntsh.so.18.1: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.3.23 (cli) (built: Sep 29 2020 12:02:26) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.23, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.23, Copyright (c) 1999-2018, by Zend Technologies
I don’t know how to solve it 😦
Its centos 6.10
Have you tried a “find” for “oci8.so”?
find / -iname oci*.so
hi.. i have some problemm. how you can solve this problem? i need your help. please. thanks
What is the problem @Stev?
Are you sure you edited the correct php.ini file? There could be more than one, also check to see you followed the steps correctly. From what i can see is you almost have it working, it should be something simple!
The error message you shared indicates Instant Client 18.1? Regardless, confirm your path to the instant client using `find / -iname libclntsh.so*`
Then make sure your environment is set for that folder. In my case (v12.2) it was the following:
sudo sh -c “echo /usr/lib/oracle/12.2/client64/lib >/etc/ld.so.conf.d/oracle-instantclient.conf”
sudo mkdir -p /usr/lib/oracle/12.2/client64/lib/network/admin
then try `php -v` again.
You could also load the -sqlplus- Instant Client package. That would allow you to confirm that the Instant Client is properly setup to connect to your database outside of the PHP environment. (tackle 1 thing at a time).
I would also recommend adding the “export” statements to /etc/sysconfig/httpd as well.
No package php-oci8 available.
According to this:
try this instead:
$ sudo yum install php-oci8-19c
If not use:
$ sudo yum install php-oci8*
or similar. Get familiar with yum commands so that it will be easier for me. The above took me about 1 minute to find on Google.