Web Analytics

Configuring PHP with Oracle support on Oracle Enterprise Linux

In case you need to run PHP with Oracle support this is how to do it with Oracle Enterprise Linux 5.x. I assume that Apache and PHP are already installed.

First you need to download the source of latest version of oci8 driver, here. Also you need to download and install the latest version of Oracle Instant Client Packages - Basic and SDK, here.

The next step is to install both packages on the system:

rpm -ivh oracle-instantclient11.2-basic-
rpm -ivh oracle-instantclient11.2-devel-

After installing the instant client, you have to build the oci8:

tar xfzv oci8-1.4.6.tgz
cd oci8-1.4.6
./configure -with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
make install

Module will be installed in PHP modules directory, which is /usr/lib64/php/modules/.

Edit php.init and add the following line to make oci8 driver to be loaded by PHP:

After restarting the web server, you now have Oracle support enabled in PHP. Oracle support could be tested from command line without restarting the web server, with this simple script:

cat > /tmp/oracle.php

$username = "scott";
$passwd = "tiger";
$conn = OCILogon($username,$passwd,$db);
if (!$conn)
    echo "Connection failed";
    echo "Error Message: [" . OCIError($conn) . "]";
    echo "Connected!";

Running the script shows that it is connecting successfully to the database:

[root@app tmp]# php oracle.php

There is also manual at PHP for installation and configuration of OCI8, which could be found here.