If you plan to use PHP to connect to an Oracle database, then you’ll want to install OCI8, which is a pecl extension for Oracle. You can also use PDO_OCI as mentioned in The Underground PHP and Oracle Manual, however Oracle does not contribute to PDO_OCI; if you look this up (for example on stackoverflow), you’ll find a number of users have had various problems getting PDO_OCI to work. So installing OCI8 is highly recommended!
Run the following command to stop Apache:
sudo service httpd stop
Install Instant Client
Go to Oracle’s instant client download page, and select the link for you Linux architecture. You’ll have to click on the “Accept License Agreement” radio button, and you’ll have to download it somewhere and then transfer it to your Red hat Enterprise Linux Server (RHEL). RHEL distro doesn’t have a GUI, but just CLI, so the easiest way might be to transfer via scp. Download the latest version and both the “basic” and “devel” RPMs.
After copying the instant client RPMs to your home directory, run the following commands to install the RPMs:
sudo rpm -Uvh oracle-instantclient12.1-basic* sudo rpm -Uvh oracle-instantclient12.1-devel*
You then need to set the ORACLE_HOME environment variable:
cd ~ vi .bashrc ORACLE_HOME=/usr/lib/oracle/12.1/client64 export ORACLE_HOME :wq!
Install Pear & Devel
In order to install OCI8, you first need to get pecl. Also pecl will need the development packages. Run the following commands:
sudo yum install php70u-pear php70u-devel
At this point you should be ready to install OCI8:
pecl install oci8
Observe the output carefully, and make sure no errors are shown. If any errors are shown, you might have to review the above to make sure you haven’t missed anything, also you might want to read through The Underground PHP Oracle Manual.
Then when oci8 is installed, you now need to edit the PHP config file to add the compiled oci8.so file:
sudo vi /etc/php.ini extension=oci8.so
Add “extension=oci8.so” at the very bottom of the file.
Verifying OCI8 is Installed
First restart Apache:
sudo service httpd restart
Then create a phpinfo() file in your Apache Document root folder, so you can access it via web browser. Then open in any browser, and then search for “oci8”. Make sure that it is enabled.