Wednesday, January 28, 2009

Installing Oracle OCI8 and PHP

I will describe here the steps I needed to install oracle connectivity for php. It's supposed you have php installed, in my case
I had php 5.1.6 throught RPM:

# rpm -qa | grep php
php-5.1.6-20.el5_2.1
php-adodb-4.81-1.el5.rf
php-pecl-mailparse-2.1.1-1.el5.rf
phpmyadmin-2.11.8.1-1.el5.rf
php-odbc-5.1.6-20.el5_2.1
php-pecl-fileinfo-1.0.4-1.el5.rf
php-cli-5.1.6-20.el5_2.1
php-pear-file-1.2.2-1.el5.rf
php-eaccelerator-5.1.6_0.9.5.2-4.el5.rf
php-pecl-memcache-2.1.2-1.el5.rf
php-pear-db-1.7.13-2.el5.rf
php-common-5.1.6-20.el5_2.1


Distro:

# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5 (Tikanga)

1. Download and install the Instant Client rpms from oracle which you can get here http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html.

This are the two files needed in my case:

# rpm -ivh oracle-instantclient11.1-basic-11.1.0.7.0-1.x86_64.rpm

# rpm -ivh oracle-instantclient11.1-devel-11.1.0.7.0-1.x86_64.rpm


2. Compile and install the oci8 extension:

Make sure you have the proper packages to compile a script like: php-devel, gcc,etc.


# pear install pecl/oci8

I used pear install pecl/oci8 instead of pear install oci8 because for some reason the second one returns an out of memory error and ignores the memory limit variable (memory_limit = XX ) from the
php.ini file.


When asked about this:

Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client : autodetect

If you have oracle installed in the same server just hit enter. If not (you just want to connect to another server) type:

instantclient and enter or the path to the oracle libraries e.g: /usr/lib/oracle/11.1/client64/lib/.


3. Finally, edit your php.ini file (/etc/php.ini) and add the extension=oci8.so in the Dynamic extensions section. Don't forget to restart apache so the changes take effect in apache.


Additional information can be found here: http://www.oracle.com/technology/pub/notes/technote_php_instant.html.

3 comments:

Anonymous said...

Thanks! I already had Oracle installed, so I didn't need to install the instant client, but your instructions saved me a bunch of time!

Muhammad said...

Hello,
I ready to follow all instruction above untill finished, and nothing wrong, so i tried to make connection using this code :

$c = oci_connect(“hr”, “hr”, “localhost/XE”);

if($c) echo “Done”;

else echo “Not yet Connected”;

nothing heapen!! any something wrong ??, so i check on phpinfo(), and there no list of OCI8.

help pleasee!!!

Regards

Anonymous said...

Thank you so much!
That really helped!