PHP – Use of undefined constant OCI_COMMIT_ON_SUCCESS/OCI8 install

Often when I move to a new box to do development, I get all happy with coding before I realise that I don’t have PHP OCI8 installed… you just get used to it being there and then you encounter the wonderful error:

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant OCI_COMMIT_ON_SUCCESS – assumed ‘OCI_COMMIT_ON_SUCCESS’


This very informative message is PHP telling you that OCI8 is not installed. Installation of the OCI8 package/module isn’t too difficult, but not near as easy as MySQL.

So, how do we install OCI8?

Thankfully, there is a good document here to get you started.
Since I’m using Ubuntu(64bit), I had to take a few extra steps:
1. Make sure you download the instant client and the sdk from oracle (two separate downloads)
2. Pick an installation directory, and create it (you can create a different one than I chose):
/usr/lib/oracle/11.2/client/lib
3. Move all the files from the instant client download (not the sdk, that’s the next step) to the installation direction created in previous step
4. Move the sdk directory to the installation directory to step 2 above
5. Create the symbolink link mentioned in the install doc from oracle:
ln -s libclntsh.so.11.1 libclntsh.so
6. Check the directory structure:
ls -la /usr/lib/oracle/11.2/client/lib

drwxr-xr-x 4 fflintstone fflintstone      4096 2012-06-28 09:12 .
drwxr-xr-x 3 root     root          4096 2012-06-28 09:09 ..
-rwxrwxr-x 1 fflintstone fflintstone     25308 2011-09-17 11:08 adrci
-rw-rw-r-- 1 fflintstone fflintstone       437 2011-09-17 11:08 BASIC_README
drwxrwxr-x 2 fflintstone fflintstone      4096 2011-09-17 11:08 demo
-rwxrwxr-x 1 fflintstone fflintstone     46228 2011-09-17 11:08 genezi
lrwxrwxrwx 1 fflintstone fflintstone        17 2012-06-28 08:41 libclntsh.so -> libclntsh.so.11.1
-rwxrwxr-x 1 fflintstone fflintstone  52761218 2011-09-17 11:08 libclntsh.so.11.1
-r-xr-xr-x 1 fflintstone fflintstone   7955322 2011-09-17 11:08 libnnz11.so
lrwxrwxrwx 1 fflintstone fflintstone        11 2012-06-28 08:54 libnnz.so -> libnnz11.so
-rwxrwxr-x 1 fflintstone fflintstone   1971762 2011-09-17 11:08 libocci.so.11.1
-rwxrwxr-x 1 fflintstone fflintstone 118408281 2011-09-17 11:08 libociei.so
-r-xr-xr-x 1 fflintstone fflintstone    164836 2011-09-17 11:08 libocijdbc11.so
-r--r--r-- 1 fflintstone fflintstone   2095661 2011-09-17 11:08 ojdbc5.jar
-r--r--r-- 1 fflintstone fflintstone   2714016 2011-09-17 11:08 ojdbc6.jar
-r-xr-xr-x 1 fflintstone fflintstone       869 2011-09-17 11:08 ott
-rw-rw-r-- 1 fflintstone fflintstone    300666 2011-09-17 11:08 ottclasses.zip
drwxr-xr-x 3 fflintstone fflintstone      4096 2012-06-28 09:12 sdk
-rw-rw-r-- 1 fflintstone fflintstone       433 2011-09-17 11:08 SDK_README
-rwxrwxr-x 1 fflintstone fflintstone    191237 2011-09-17 11:08 uidrvci
-rw-rw-r-- 1 fflintstone fflintstone     66779 2011-09-17 11:08 xstreams.jar

7. Let PECL do the dirty work:
pecl install oci8
8. PECL will ask for input Please provide the path to the ORACLE_HOME directory, give it the install directory you created in step 2 above:
instantclient,/usr/lib/oracle/11.2/client/lib
9. Enable the OCI8 extension:
vi /etc/php5/conf.d/oci.ini
10. Contents of /etc/php5/conf.d/oci.ini:

; configuration for php OCI module
extension=oci8.so

11. Restart Apache
12. Check for install through cli:
php -i | grep oci
The above command should produce output similar to:

/etc/php5/cli/conf.d/oci.ini,
oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20

~ by ityndall on June 28, 2012.

Leave a Reply