How To Build PDO_OCI in Ubuntu 12.04

Building PDO_OCI extension in Ubuntu 12.04 is a little difficult. The reason :
a. pdo extension are included in the php5 package
b. PDO_OCI in pecl requires pdo extension source, not pdo extension binary
c. pdo from pecl cannot compile under php 5.3
c. malformed tgz resulting from 'pecl download PDO_OCI' (well, as of today, 11-07-2014, it is)
Why I need PDO_OCI? Well, I used Yii framework and need to access oracle database.

Yesterday I tried this strategy to obtain pdo_oci extension :
1. downloaded instant client 10.2.0.4 basic and sdk from OTN (oracle tech network)
2. extract the instant client files, move them to  /opt/instantclient_10_2, create 3 symbolic links.
3. download php5 source package, and try to rebuild the php5 debs using debuild. This would ensure the php extensions were build.
apt-get install dpkg-dev
apt-get source php5
apt-get build-dep php5
apt-get install devscripts
debuild -us -uc

4. after php5 deb created, change the debian/rules file to enable the pdo_oci compilation by inserting a with-pdo-oci line :
                --with-pdo-odbc=shared,unixODBC,/usr \
                --with-pdo-pgsql=shared,/usr/bin/pg_config \
                --with-pdo-oci=shared,instantclient,/opt/instantclient_10_2,10.2.0.4 \
                --with-pdo-sqlite=shared,/usr \
Note that there are 4 parameters for with-pdo-oci that need to be specified. The first parameter makes an pdo_oci extension instead of statically compiling it. The second states that we will use oracle instant client driver. The third tells the location of the instant client files. The fourth explicitly states instant client version we have, because the autodetection doesn't work very well.
5. Rebuild using debuild, and copy the resulting so to the modules folder.
cp debian/libapache2-mod-php5/usr/lib/php5/20090626+lfs/pdo_oci.so /usr/lib/php5/20090626+lfs/
Thats as far I can recall. If something were inadvertently omitted, I would have to update this post.

Tips :

1. The linker would skip the instant client shared library (.so) if the architecture doesn't match. For example, it would skip the instant client .so if the downloaded instant client is for 64bit architecture and we are on 32bit linux.
2. Locale errors could be fixed by installing language-pack-de and executing locale-gen from root.
apt-get install language-pack-de

3. Three symbolic links should be created for instantclient :
ln -s /opt/instantclient_10_2/libclntsh.so.10.1 /opt/instantclient_10_2/libclntsh.so
ln -s /opt/instantclient_10_2/libocci.so.10.1 /opt/instantclient_10_2/libocci.so
ls -s /opt/instantclient_10_2/lib opt/instantclient_10_2
4. Enable yii schema caching to reduce long delays caused by inefficient data dictionary queries in the Oracle database

Comments

Popular posts from this blog

Long running process in Linux using PHP

Reverse Engineering Reptile Kernel module to Extract Authentication code

SAP System Copy Lessons Learned