Installing OCI8 extension for PHP 5.4 debian wheezy (x86)

“Welcome to the oracle hell”… Just read that on the php OCI8 man page and it’s true. Installing OCI8 extension wasn’t hard but took a lot of googling time… I’m describing here what I did to accomplish this hard task.

First of all, download those both files from the official Oracle website:

Put them on your server, and convert them to .deb files with alien for example and install :

apt-get install alien

# Converting to deb
alien -d oracle-instantclient11.2-basic-
alien -d oracle-instantclient11.2-devel- 

# Installing

dpkg -i oracle-instantclient11.2-devel_11.
dpkg -i oracle-instantclient11.2-basic_11.

Now it’s becoming tricky, as the PHP documentation says it should be done in one command pecl install oci8, but don’t dream it’ll rarely work…

So, after trying, I’ll do it the manual way :

# Downloading oci8
pecl download oci8
tar xzf oci8-2.0.7.tgz
cd oci8-2.0.7
# I had an error there 1)

# And there too 2)

# Once you've succeded you can do
make install

# Add the oci8 extension to the /etc/php5/cli/php.ini and test with :
php -v

# If it shows an error extension isn't loaded 3)

1) configure error No such file or directory

The path to the ORACLE_HOME should be automatically detected, if not export ORACLE_HOME=/usr/lib/oracle/11.2/client/ and try again!

2) make error No such file or directory

If it doesn’t find a header file (i.e: oci.h: No such file or directory) you should export C_INCLUDE_PATH=/usr/include/oracle/11.2/client.

3) php -v almost done…

While trying with the php -v command it throwed :

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20100525+lfs/' - cannot open shared object file: No such file or directory in Unknown on line 0

Hopefully it wasn’t a big deal and the solution was :

sudo apt-get install libaio1

That doesn’t look hard like hell, but it was! Glad it’s done and fully working as the phpinfo() mentions OCI8 Support enabled.

## Compiling PHP with PDO OCI

First check if aspx2 is available, if not :

sudo apt-get install apache2-prefork-dev

According to dpkg -l | grep apache2.

Set your $ORACLE_HOME (export ORACLE_HOME=/usr/lib/oracle/11.2/client/), download php and extract it.

./configure --with-pdo-oci --with-oci8 --with-apxs2=/usr/bin/apxs2 --with-mysql --with-pdo-mysql
sudo make install
sudo service apache2 restart

More options

./configure --with-apxs2=/usr/bin/apxs2 --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-dba --enable-exif --enable-ftp --with-gd --with-gettext --with-imap --with-imap-ssl --with-kerberos --enable-mbstring --with-mcrypt --with-openssl --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-wddx --enable-zip --with-zlib --with-xsl --with-mysql --with-mysqli --with-pgsql --with-pdo-mysql --with-pdo-pgsql --with-oci8 --with-pdo-oci

On Debian :