Friday, July 15, 2011

How to connect using PHP to Oracle DB

Hi again. Today an brief explanation about how to install OCI8 for PHP.

1) We need to install PEAR

$sudo apt-get install php-pear libaio1 php5-dev

php-pear the PHP extensión
libaoi1 is th Linux kernel AIO access library
php5-dev because we need the command phpize

2) Download the Oracle Instant Client from the official Oracle website (you need to create an account) and download the files

instantclient-basic-linux32-XX.X.X.X.X.zip
instantclient-sdk-linux32-XX.X.X.X.X.zip

3) Create your own tree of directories

$ sudo mkdir -p /opt/oracle
$ sudo cd /opt/oracle
$ sudo unzip instantclient-basic-linux32-XX.X.X.X.X.zip
$ sudo unzip instantclient-sdk-linux32-XX.X.X.X.X.zip
$ sudo mv instantclient_XX_X instanclient

4) Set some soft links
$ sudo ln -s libclntsh.so.10.1 libclntsh.so
$ sudo ln -s libocci.so.10.1 libocci.so

5) Install the OCI module (needs php5-dev)
$sudo pecl install oci8
...
[path]: instantclient,/opt/oracle/instantclient

6) Add to /etc/php5/apache/php.ini the line
extension=oci8.so

7) Reset apache services and... voila!!

Hope help

No comments:

Post a Comment