Sunday, April 24, 2011

Ubuntu 10.04 LTS with OCI8

Finally, Akhirnyaaaaaaaaaaaaaaaaa!!! Alhamdulillah berjaya configurekan Ubuntu LAMP Server untuk work together with OCI8 (Oracle Call Interface)... yang membolehkan connection ke database Oracle possible!!! Thanks to the author of this tutorial... here it is.... \(^o^)/

To be able to access Oracle databases from PHP, you will need to have PHP compiled / linked with the Oracle OCI (oci8) library.

You could use the pre-built PHP 5 from Zend or there are two other ways to get PHP working with OCI8:

  1. Install the Oracle Database [Oracle10g] [Oracle9i]
  2. Install Oracle Instant Client

If your Oracle database is in another machine, the Oracle Instant Client is a smaller install.

PHP using Oracle Database Server

TODO

PHP using Oracle Instant Client

Tested Environment:

Ubuntu Server 10.04 LTS Oracle Instant Client 11.2

Prerequisites:

sudo apt-get install build-essential
sudo apt-get install php5-dev php-pear libaio1

Instant Client installation requires some environment variables to be able to see the library folder. Edit /etc/environment and add at the end:

# Oracle Instant Client
LD_LIBRARY_PATH="/usr/local/lib/instantclient_11_2"
TNS_ADMIN="/usr/local/lib/instantclient_11_2"
ORACLE_BASE="/usr/local/lib/instantclient_11_2"
ORACLE_HOME=$ORACLE_BASE

Then download the Oracle Instant Client from Oracle.com another (you will need to create an account)

You will need the Basic (48MB) and SDK (600K). The Basic Lite version does not work.

cd /usr/local/lib
sudo unzip
sudo unzip
cd instantclient_11_2
sudo ln -s libclntsh.so.11.1 libclntsh.so

The symbolic link is needed by during the compilation step later.

sudo pecl install oci8

You will be prompted for the location of the library:

instantclient,/usr/local/lib/instantclient_11_2

You will be prompted also for the ORACLE_HOME location, type 'all', accept and then insert:

instantclient,/usr/local/lib/instantclient_11_2

If successful, you may now add the following line at the bottom of php.ini

extension=oci8.so

The php.ini is found in 2 places: /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini

sudo /etc/init.d/apache2 reload
Check to verify if the OCI8 module is available.