Tuesday, July 22, 2008

PHP + OCI8 + instantClient

We need to install PHP support OCI8 1.3.X (this is new oci8 support 11g, that can create connection pool) with instantClient (download basic- + sdk-


1. Used Linux x86_64
2. Installed Apache2 HTTP at /usr/local/apache/ PATH.

After that We install PHP =>

Begin -> download instantClient + SDK and install:

$ mkdir /oracle
$ cd /oracle
$ unzip /tmp/basic-
Archive: /tmp/basic-
inflating: instantclient_11_1/BASIC_README
inflating: instantclient_11_1/adrci
inflating: instantclient_11_1/genezi
inflating: instantclient_11_1/libclntsh.so.11.1
inflating: instantclient_11_1/libnnz11.so
inflating: instantclient_11_1/libocci.so.11.1
inflating: instantclient_11_1/libociei.so
inflating: instantclient_11_1/libocijdbc11.so
inflating: instantclient_11_1/ojdbc5.jar
inflating: instantclient_11_1/ojdbc6.jar

$ unzip /tmp/sdk-
Archive: /tmp/sdk-
creating: instantclient_11_1/sdk/
creating: instantclient_11_1/sdk/include/
inflating: instantclient_11_1/sdk/include/occi.h
inflating: instantclient_11_1/sdk/include/occiCommon.h
inflating: instantclient_11_1/sdk/include/occiControl.h
inflating: instantclient_11_1/sdk/include/occiData.h
inflating: instantclient_11_1/sdk/include/occiObjects.h
inflating: instantclient_11_1/sdk/include/occiAQ.h
inflating: instantclient_11_1/sdk/include/oci.h
inflating: instantclient_11_1/sdk/include/oci1.h
inflating: instantclient_11_1/sdk/include/oci8dp.h
inflating: instantclient_11_1/sdk/include/ociap.h
inflating: instantclient_11_1/sdk/include/ociapr.h
inflating: instantclient_11_1/sdk/include/ocidef.h
inflating: instantclient_11_1/sdk/include/ocidem.h
inflating: instantclient_11_1/sdk/include/ocidfn.h
inflating: instantclient_11_1/sdk/include/ociextp.h
inflating: instantclient_11_1/sdk/include/ocikpr.h
inflating: instantclient_11_1/sdk/include/ocixmldb.h
inflating: instantclient_11_1/sdk/include/odci.h
inflating: instantclient_11_1/sdk/include/oratypes.h
inflating: instantclient_11_1/sdk/include/ori.h
inflating: instantclient_11_1/sdk/include/orid.h
inflating: instantclient_11_1/sdk/include/orl.h
inflating: instantclient_11_1/sdk/include/oro.h
inflating: instantclient_11_1/sdk/include/ort.h
inflating: instantclient_11_1/sdk/include/xa.h
inflating: instantclient_11_1/sdk/include/nzt.h
inflating: instantclient_11_1/sdk/include/nzerror.h
creating: instantclient_11_1/sdk/demo/
inflating: instantclient_11_1/sdk/demo/demo.mk
inflating: instantclient_11_1/sdk/demo/cdemo81.c
inflating: instantclient_11_1/sdk/demo/occidemo.sql
inflating: instantclient_11_1/sdk/demo/occidemod.sql
inflating: instantclient_11_1/sdk/demo/occidml.cpp
inflating: instantclient_11_1/sdk/demo/occiobj.cpp
inflating: instantclient_11_1/sdk/demo/occiobj.typ
inflating: instantclient_11_1/sdk/SDK_README
extracting: instantclient_11_1/sdk/ottclasses.zip
inflating: instantclient_11_1/sdk/ott

$ cd instantclient_11_1/

create link libraries:
$ ln -s libclntsh.so.11.1 libclntsh.so
$ ln -s libocci.so.11.1 libocci.so

Download PHP + new OCI8 (http://oss.oracle.com) and then patch OCI8 + install PHP with Apache2:

$ tar zxvf php-5.2.6.tar.gz
$ cd php-5.2.6/ext/
$ mv oci8 oci8-old
$ tar zxvf /tmp/oci8-1.3.x.tgz
$ ln -s oci8-1.3.x oci8
$ cd ..

$ export ORACLE_HOME=/oracle/instantclient_11_1/
$ pwd

$ ./configure --prefix=/usr/local/apache --with-config-file-path=/usr/local/apache/conf \
--enable-sigchild --with-apxs2=/usr/local/apache/bin/apxs \

$ make

$ su # use "root" user to install

$ make install

copy file (php.ini-dist or php.ini-recommended) for php.ini
$ cp php.ini-dist( or php.ini-recommended) /usr/local/apache/conf/php.ini

Add Type in httpd.conf file and start Apache2
AddType application/x-httpd-php .php

>>> create tnsnames.ora file "/oracle/instantclient_11_1/tnsnames.ora"

DB =
(ADDRESS = (PROTOCOL = TCP)(HOST = db_host)(PORT = 1521))


Anyway, before start apache, we should set ORACLE ENV:


The NLS_LANG and TNS_ADMIN variables are most likely to be required for Zend Core for Oracle. Zend Core for Oracle modifies apachectl and adds LD_LIBRARY_PATH. (This may not be required in a future version of Zend Core for Oracle if Oracle links the Instant Client differently).

This allows the Zend Core for Oracle GUI Console to be reused to start Apache. If you are using a tnsnames.ora fi le and specify network aliases for the connection string with Zend Core for Oracle, you may need to do something similar with TNS_ADMIN so the Zend Core for Oracle Console can restart Apache correctly. If you start Apache manually, set the environment in a calling script.

>>> This case we created "tnsnames.ora" file at /oracle/instantclient_11_1/ PATH, So

$ export TNS_ADMIN=/oracle/instantclient_11_1/

$ /usr/local/apache/bin/apachectl start

create Code to test PHP + Oracle =>

$c = oci_connect('username', 'password', 'db');

We can find out PHP + Oracle at http://www.oracle.com/technology/tech/php/index.html

No comments: