This guide is intended to work for systems running Ubuntu 14.04 LTS, and PHP 5.5.9-1ubuntu4.19.

Installing Oracle DB access is pretty tricky, there are even Github repositories set aside to provide up to date python scripts to do this.
But it’s just as possible to do this manually. So here we go…

Step 1: Perform an update/upgrade

sudo apt-get update
sudo apt-get upgrade

Step 2: Installing PECL

Source: http://askubuntu.com/questions/403327/install-pecl-packages-on-ubuntu

sudo apt-get install php-pear
sudo apt-get install php5-dev
sudo apt-get install libcurl3-openssl-dev

Note: If you’re running PHP7, you’ll need to run:

sudo apt-get install php7.0-dev

instead of:

sudo apt-get install php5-dev

Step 3: Installing Oracle’s OIC (Downloading Files)

Source: https://help.ubuntu.com/community/Oracle%20Instant%20Client

First, go to: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

And go to the download page that matches your server.

You can use the following command to determine if you’re running a 32 or 64 bit of Ubuntu. If you’re running a 64 bit version, the response will be: x86_64.

uname -m

You’ll need to download the following .RPM files from Oracle’s page:

  • Basic: (Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications)
  • SQLPlus: (Instant Client Package – SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client)
  • SDK: (Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client)

Step 4: Installing Oracle’s OIC (Installing the .RPMs)

Once you have these .rpm files downloaded/copied onto the Ubuntu server (into your /home/username/ directory or any directory is fine.)

You’ll need to cd to the directory containing them, and run the following commands:

sudo apt-get install alien

This will install the program necessary to convert/install .RPM packages as .DEB packages for Ubuntu.

Once it’s down installing, run:
Note: The filenames may be different if you’re not using version 12.1.0.2.0-1.x86_64

sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
sudo alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
sudo alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

Step 5: Configure ORACLE_HOME

Run:

sudo nano /etc/profile.d/oracle.sh

Add the following two lines to the file:

export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export PATH=$PATH:$ORACLE_HOME/bin

Save the file then run:

sudo chmod o+r /etc/profile.d/oracle.sh

Next, run the commands directly that were saved to the file.

export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export PATH=$PATH:$ORACLE_HOME/bin

Your ORACLE_HOME variable should now be available for your system.

Step 6: Integrate Oracle Libraries

Run:

sudo apt-get install libaio1

Then create the file:

sudo nano /etc/ld.so.conf.d/oracle.conf

Add the line:

/usr/lib/oracle/12.1/client64/lib/

And save the file.

Then run:

sudo chmod o+r /etc/ld.so.conf.d/oracle.conf
sudo ldconfig

Step 7: Installing PECL’s OCI8

Since we’re using PHP 5.5.9 and as of this writing the latest PECL supports PHP 7 we’ll need to apt-get an older version.

Source: https://pecl.php.net/package/pecl_http

This page will have the stable builds that will suit whichever PHP version you may have installed however.

In our case, we’ll need to run:

sudo pecl install oci8-2.0.12

Note: if you DO have PHP7 or latest, simply use the command:

sudo pecl install oci8

^Source: https://pecl.php.net/package/oci8

When it asks for the input we’ll use:

instantclient,/usr/lib/oracle/12.1/client64/lib

Step 8: Configure php.ini files

This version of the server is using apache2 so it will need to modify the following php.ini files

Run:

For PHP5:

sudo nano /etc/php5/cli/php.ini

For PHP7:

sudo nano /etc/php/7.0/cli/php.ini

At the very end of the file add the line:

extension=oci8.so

Then again for apache2’s php.ini file

Run:

For PHP5:

sudo nano /etc/php5/apache2/php.ini

For PHP7:

sudo nano /etc/php/7.0/apache2/php.ini

At the very end of the file add the line:

extension=oci8.so

Note: Do this for any php.ini files located in folders within /etc/php5/
In this case the only folders I found were apache2 and cli, your install might have other folders depending on other factors.

Also Note: There is a fancier way of doing this of using: echo but I ran into issues with privileges even with using sudo.

Step 9: Restart Apache

Restart apache by running:

sudo service apache2 restart

Step 10: Testing the Install

Go to your web directory (assumed /var/www/html/ ) and create the following PHP file.

<?php

 ini_set('display_errors', 1);
 ini_set('display_startup_errors', 1);
 error_reporting(E_ALL);

 $userName = "USERNAME";
 $userPW = "PASSWORD";
 $hostAddr = "yourdbaddress.com";
 $portNum = "1234";
 $serviceName = "ABC123";

 $db="(DESCRIPTION=
  (ADDRESS_LIST=
  (ADDRESS=(PROTOCOL=TCP)
  (HOST=" . $hostAddr . ")(PORT=".$portNum.") ) )
  (CONNECT_DATA=(SERVICE_NAME=".$serviceName.") ) )";

 $dbLogon = ocilogon($userName, $userPW,$db);

 $query = "SELECT sysdate FROM dual";
 $stmt = ociparse($dbLogon,$query);

 if (!OCIExecute($stmt))
 {
  $oerr = OCIError($stmt); echo "Execute Code:" . $oerr["code"];
  if ($oerr["code"]) $log = "Unable to execute Usage query.&amp;amp;lt;br&amp;amp;gt; Error:" . $oerr["message"];
 }

 if (ocifetchinto($stmt,$row,OCI_NUM))
 {
  print_r($row);
 }
>

Note: You’ll need to replace the variables:

$userName = "USERNAME";
$userPW = "PASSWORD";
$hostAddr = "yourdbaddress.com";
$portNum = "1234";
$serviceName = "ABC123";

with your details for your schema.

The code should return back sysdate from dual (the current date from Oracle’s system DB)

You can also perform an Ubuntu line test of SQLPlus to see if that is working correctly as well.