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-11.2.0.3.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

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

tar xfzv oci8-1.4.6.tgz
cd oci8-1.4.6
phpize
./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:
extension=oci8.so

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

<?php
$username = "scott";
$passwd = "tiger";
$db="(DESCRIPTION=
       (ADDRESS_LIST=
         (ADDRESS=(PROTOCOL=TCP)
           (HOST=192.168.8.36)(PORT=1521)
         )
       )
         (CONNECT_DATA=(SERVICE_NAME=orcl))
  )";
$conn = OCILogon($username,$passwd,$db);
if (!$conn)
{
    echo "Connection failed";
    echo "Error Message: [" . OCIError($conn) . "]";
    exit;
}
else
{
    echo "Connected!";
}

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

[root@app tmp]# php oracle.php
Connected!

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

Regards,
Sve