Debian, PHP and Oracle

So I had been trying to get PHP on a Debian system to talk to our Oracle database for a while, and it had been nagging me for long enough that I decided to post my solution here.

A bit of context:

I needed to get connectivity to our Oracle database on a Debian Etch x86_64  
installation. Oracle provides the [Oracle Instant Client](http://www.oracle.com/technology/tech/oci/instantclient/index.html) (OCI), for which  
PHP [has support](http://us2.php.net/oci8).  

The Debian packages for PHP however were not compiled with OCI support,  
but you can recompile your own and enable it:  
  • get the current OCI release (the patch below assumes you grab 11.1 which is currently the latest)
  • unzip to /usr/local/OCI (if you use a different location you'll have to change the patch accordingly)
  • set your LD_LIBRARY_PATH to /usr/local/OCI

  • create some symlinks. I'm not 100% sure this is needed but I suppose it doesn't hurt

libclntsh.so -> libclntsh.so.11.1
libocci.so -> libocci.so.11.1

  • get the php5 package source: apt-get source php5
  • install all dependent packages: apt-get build-dep php5 (the Debian Developer Reference is a very useful resource)

  • apply this patch to your tree. this is the core piece. you may have to tweak it depending on OCI version and install location. basically passing --with-oci8 to apache2 module config and setting appropriate version numbers

  • rebuild packages: dpkg-buildpackage -rfakeroot
  • TADA!

You will also need to add the LD_LIBRARYPATH to your /etc/init.d/apache2_ script so it finds the OCI libraries on startup.

Comments

Comment 1 by TTimo

Update!

Just had to do this again, on a Debian Sid system with the full Oracle 11g installed rather than instant client. The set of changes seemed easier this time around:

in debian/rules, added to the configure-apache2-stamp target:
--with-oci8=/opt/app/oracle/product/11.1.0/db_1

You'll have to adapt that to your installation path, or the OCI path if you are doing it with OCI etc.

The build goes as usual, but I hit a problem with dpkg-shlibdeps because libclntsh.so is in the dependencies but dpkg doesn't have a package for it. Added the following line to /etc/dpkg/shlibs.override:

<version/soname>

libclntsh 11.1

Also if you're having trouble passing the tests, raise the memory limit in your apache2 php.ini