Outils personnels
Vous êtes ici : Accueil GNU / Linux Debian Installer le support OCI8 pour PHP5 sur Debian 4.0 Etch et 5.0 Lenny
Actions sur le document
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Install OCI8 extension for PHP5 on Debian 4.0 Etch and 5.0 Lenny

Par Pierre-Yves Landuré - Dernière modification 18/08/2011 13:35

Due to commercial licenses of Microsoft SQL Server and Oracle, php5-oci8 and php5-mssql packages are not available from Debian repositories. This article help you to build your own packages.

Concerning MSSQL

For a long time, this guide presented the creation of php5-mssql packages. This was not required. The fact is that MSSQL functions are provided by the php5-sybase package. To use MSSQL, you just need to install this package :

/usr/bin/apt-get install php5-sybase

Note : In case you use the Symfony framework, you need to disable the automatic date conversion :

/bin/sed -i -e 's/^.*\(mssql\.datetimeconvert\).*/\1 = Off/' /etc/php5/*/php.ini


Installing OCI packages

First, we add the oracle repository to our apt configuration :
/bin/echo "# Oracle repositories for debian unstable
deb http://oss.oracle.com/debian unstable main non-free" \
| /usr/bin/tee /etc/apt/sources.list.d/unstable-oracle.list

We download the key signing this repository :

/usr/bin/wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle  -O- |  /usr/bin/apt-key add -

We update the available packages list :

/usr/bin/apt-get update

And we install the Oracle software needed to build php5-oci8 :

/usr/bin/apt-get install oracle-xe-client

Installing dependencies

First, we install packages needed to build PHP5 :

/usr/bin/apt-get build-dep php5

We install the fakeroot tool that allow to build PHP5 packages without being root :

/usr/bin/apt-get install fakeroot

We download PHP5 sources :

/bin/mkdir ~/SOURCES
/usr/bin/apt-get source php5

We change directory to the root of PHP 5 sources :

cd ~/SOURCES/php5-*

Patching the sources for php5-oci8

We detect the path to the Oracle client:

ORACLE_CLIENT=$(find /usr/lib/oracle/xe/app/oracle/product/ -name 'client' | sort --reverse | head --lines=1)

We edit the modulelist file :

/bin/echo "oci8 OCI8" | /usr/bin/tee -a debian/modulelist
We edit the rules file :
/bin/echo ${ORACLE_CLIENT} | /bin/sed -e 's|/|\\/|g' | \
/usr/bin/xargs -iCLIENT /bin/sed -i -e '/--with-mysql=shared,\/usr/i\
\t\t--with-oci8=shared,CLIENT \\' debian/rules

We edit the control file :

/bin/echo "Package: php5-oci8
Architecture: any
Depends: \${shlibs:Depends}, \${misc:Depends}, \${php:Depends}, php5-common (= \${Source-Version}), oracle-xe-client
Description: OCI8 module for php5
This package provides a module for OCI8 using Oracle 10g Express client.
PHP5 is an HTML-embedded scripting language. Much of its syntax is borrowed
from C, Java and Perl with a couple of unique PHP-specific features thrown
in. The goal of the language is to allow web developers to write
dynamically generated pages quickly.
" | /usr/bin/tee -a debian/control

We add the build dependencies to the control file :

/bin/sed -i -e 's/\(Build-Depends: .*\)/\1, oracle-xe-client/' debian/control

We create the configuration needed by dpkg-shlibdeps to work propely:

/bin/echo "libclntsh 10.1 oracle-xe-client(>=" \
| /usr/bin/tee -a debian/shlibs.local

Building the patched sources

Now, we can build our PHP 5 packages :

/usr/bin/dpkg-buildpackage -rfakeroot

If everything went well, you now have a package for and OCI8 PHP 5 extension. Since it can be used with the standard Debian PHP5, you can install it with :

cd ..
/usr/bin/dpkg -i ~/SOURCES/php5-oci8*.deb

Don't forget to restart your HTTP server. For example :

/etc/init.d/apache2 force-reload

Configuring OCI8

You now need to configure the OCI8 module, and the Oracle client.

We detect the path of the Oracle client :

ORACLE_CLIENT=$(find /usr/lib/oracle/xe/app/oracle/product/ -name 'client' | sort --reverse | head --lines=1)

We tell our system where to find the Oracle client and its configuration files. In order to do this, we need to modify /etc/environment :

/bin/echo ${ORACLE_CLIENT} | \
/usr/bin/xargs -iCLIENT sudo sh -c "echo 'ORACLE_HOME=CLIENT
| /usr/bin/tee -a /etc/environment"

Note : You can modify this command line to fit your needs if the NLS_LANG configuration does not fit you.

In the same file, we change the PATH so that it contain de binaries files for Oracle client :

/bin/echo "${ORACLE_CLIENT}/bin" | /bin/sed -e 's|/|\\\\/|g' | \
  /usr/bin/xargs -iCLIENT /bin/sed -i -e 's/PATH="\(.*\)"/PATH="\1:CLIENT"/' /etc/environment

Then, we do the same change to the users PATH :

echo "PATH=\$PATH:$ORACLE_HOME/bin" | /usr/bin/tee -a /etc/profile

After this, we reload the configuration we just changed (Thank you Renaud):

source /etc/environment

You also need to configure Apache 2 (if it is the HTTP server you use) :

/bin/echo ${ORACLE_CLIENT} | \
xargs -iCLIENT sudo sh -c "echo 'export ORACLE_HOME=CLIENT
export TNS_ADMIN=/etc/oracle
| /usr/bin/tee -a /etc/apache2/envvars"

We create the Oracle client configuration folder :

/bin/mkdir /etc/oracle

We configure our database connection parameters :


And we create the configuration file for the Oracle client :

/bin/echo "$ORA_DB = (DESCRIPTION =
)" | /usr/bin/tee -a /etc/oracle/tnsnames.ora

Note: You can use the two last commands as many time you want if you have to connect to more than one database or server.

If everything went well, you can now use Oracle clients (sqlplus for example) and the php5-oci8 extension.



Posté par Serge le 21/03/2008 11:05
Thanks very much, this article is very good.


Posté par Georg Zimmer le 25/03/2008 14:23
This worked flawlessly.


Posté par Viv Diwakar le 26/03/2008 02:10
Brilliant! Brilliant, brilliant, brilliant! This is exactly the methods i have been looking for. this is a great help!

nice guide

Posté par Renaud le 17/04/2008 10:45
Thanks for that guide, was pretty straightforward and got almost no problems with it by copy/pasting everything.
Only some remarks:

- you could maybe note that the user has to log off or source environment after adding the ORACLE_* env vars to it, as some next steps use that variable to populate other files (/etc/profile etc)
- in the very last step, there is an extra "quote" after tnsnames.ora that doesnt have to be there


Thank you

Posté par Pierre-Yves Landuré le 17/04/2008 20:16
Thank you very much for your feedback and contribution. I've just updated the guide.

mssql_connect won't work?

Posté par Schu le 19/05/2008 15:57

i built everything for mssql like in your howto and it seems to work out as planned (after lots of compiling lines i get a whole bunch of packages, among them php5-mssql...) and i installed the php5-mssql package and did an apache2 restart - but after that i still get php's "Call to undefined function mssql_connect()" error.

any idea would be appreciated...

re: mssql_connect won't work?

Posté par Schu le 19/05/2008 16:00
ok, please ignore my post, seems like my apache did not restart as planned - after shutdown and restart of the system it worked out. thank you very much for this howto!


Posté par Marco le 21/06/2008 11:49
Thanks very much for your help.

Marvelous job

Posté par Marcelo le 14/09/2008 05:59
Simple and direct. If all computer guides were so Straightforward as yours, learning wouldnt be so time demanding. I was on deadline to setup 2 web servers and your guide was a life saver :) Many many thanks!!

Very good howto

Posté par Vide le 11/12/2008 13:04
Very good post, useful and direct, thanks a lot!
Just a quick note for the ones willing toi install the Oracle client on a spare machine. There are somo minimum HW requirements you have to obey: >=256MB of RAM and <=500MB swap space.

If you have a smaller swap partition, you can create a swap file

# dd if=7dev/zer of=/swap.file bs=1M count=512
# mkswap /swap.file
# swapon /swap.file

Now you can install the oracle client without a glitch :)

thanks, and note on security

Posté par Maarten le 15/04/2009 18:01
Exellect post, thanks saved me lots of work!

a security note: when updating /etc/profile do not use $PATH (the current path value is substituted, but use \$PATH.
This makes sure the rules befor in /etc/profile are taken into account for all users.

echo "PATH=\$PATH:$ORACLE_HOME/bin" | /usr/bin/tee -a /etc/profile


Posté par Hugo Segura le 03/06/2009 17:37
Very good explanations .... should add: Only works for i386 architecture (amd64 is not supported by oracle)

support for amd64

Posté par fraff le 14/05/2012 15:29
for amd64 support, you'll need to install oracle-instantclientXX.X-basic (where XX.X is the version) from rpm to deb using alien AND oracle-xe-client for x86 using dpkg --force-architecture

then, install ia32-libs

# this is where libclntsh.so is
ORACLE_CLIENT=$(dpkg -L oracle-instantclientXX.X-basic | grep lib$ | tail -1)

# this is where to find oci.h
ORACLE_INCLUDE=$(dpkg -L oracle-xe-client | grep "oci.h" | tail -1 | sed 's/oci.h//')

# this specify lib and include dir to compiler

the rest is unchanged ...

what a wonderful howto!

Posté par Cristian le 02/07/2009 17:05
I will loose my job... nothing to do.. only execute your code.


Posté par Euforia le 04/08/2009 13:56
Thanks for this handy guide!


Posté par Bert le 17/03/2010 13:52
Thank you for this handy guide! How do you do apt-get (dist-)upgrades? Just recompile?

God bless you!

Posté par Nicholas Vahalik le 16/09/2010 15:41
I have searched everywhere for instructions on how to do this. This guide was excellent! There were a couple of changes that I had to make on my lenny system, though.

\t\t--with-oci8=shared,CLIENT \\

Needed to be:

\t\t--with-oci8=shared,CLIENT \\

Again, thank you very much!

adopt to Squeeze

Posté par qrtalaci le 11/02/2011 00:48
-the control file needs one new-line before "Package: php5-oci8...
-the comma should be moved:
/bin/sed -i -e 's/\(Build-Depends: .*\)/\1 oracle-xe-client, /' debian/control
instead of
/bin/sed -i -e 's/\(Build-Depends: .*\)/\1, oracle-xe-client/' debian/control
-don't do it with the root account (MySQL tests will fail!):
/usr/bin/dpkg-buildpackage -rfakeroot
-IMPORTANT: after this last command submitted 275-277 lines of ext/oci8/oci8_interface.c should be commented out (for example with //s) or like this:
/*if (strlen(filename) != filename_len) {


Posté par Tim Turnquist le 09/08/2011 18:36
I really appreciate these instructions, but I get to the command:
/usr/bin/dpkg-buildpackage -rfakeroot
and this command runs for about 30 - 40 minutes then errors with these lines:
oci8_interface.c: error: 'filename' undeclared (first use in this function)
oci8_interface.c: error: (each undeclared identifier is reported only once
oci8_interface.c: error: for each function it apears in.)
oci8_interface.c: error: 'filename_length' undeclared (first use in this function)
make[1]: *** [etc/oci8/oci8_interface.lo] Error 1
make[1]: Leaving directory '/home/dev/SOURCES/php5-5.3.2/apache2-build'
make: *** [build-apache2-stamp] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2

I am using Ubuntu-10.04.3-server-i386.

I needed to make a modification to $ORACLE_CLIENT since the value as instructed here left me with '/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/logs/client' and I think it should have been '/usr/lib/oracle/xe/app/oracle/product/10.2.0/client', which is exactly what that command gives me if I remove the | sort --reverse parameter. Should it be something else? Also, I do not have a folder that is referred to in the error: /etc/oci8 does not exist on my system. Did I miss something?

Please help!

Old guide

Posté par LoneWolf le 09/08/2011 18:58

this guide is outdated, try :


it is in french, but i hope the command lines will help.

Lone Wolf


Réalisé avec Plone

Ce site respecte les normes suivantes :