How to install PHP PDO_OCI on Ubuntu Gutsy

UPDATED guide for >=Jaunty

1) prerequisites

First of all we’ll install the php5-dev package which contains some utilities we’ll need for the build process:

sudo apt-get install php5-dev

then you’ve to find out your ORACLE_HOME environment variable, try executing:

env | grep ORACLE_HOME=

If this command outputs something like:

ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server

then you can jump to section “2) Getting and compiling PDO_OCI” otherwise go on thru this section.

If this guide we’ll just see how to find out which is your ORACLE_HOME directory if you’ve installed the oracle-xe server package. If you’ve installed instantclient or anything else please refer to the product documentation. So you’ve an installed and configured oracle-xe instance on your machine, now type:

cat /etc/init.d/oracle-xe |grep ORACLE_HOME=

the command should print something like:

ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server

now we’ve to export this variable to the current terminal session, we’ll do that with this command:

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server

and the environment variable will be configured.

2) Getting and compiling PDO_OCI

Just cut and paste these simple commands to download PDO_OCI from the web and prepare it for the build phase:

cd /tmp
pecl download pdo_oci
tar xvfz PDO_OCI-1.0.tgz
cd PDO_OCI-1.0
phpize
mkdir include
ln -s /usr/include/php5/ include/php

now everything should be setup and we can build the driver and install it with:

make && make install

If everything is fine you can continue

3) Configuring PHP and Apache

if everything is fine you can go on editing your php.ini file and adding this line:

extension=pdo_oci.so

now create a phpinfo.php file under your apache’s document root, containing this line:

<?php phpinfo();

point your browser to:

http://localhost/phpinfo.php

and search for the “environment” section, it should look like the one in the next screenshot:
environment variables
if you see the ORACLE_HOME line everything it’s ok, jump to the “4) Closure” section otherwise edit /etc/apache2/envvars file and add the ORACLE_HOME configuration, it will be something like this (on a single line):

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server

4) Closure

Restart your apache and you’re done:

sudo /etc/init.d/apache2 restart

Share/bookmark:
Digg StumbleUpon Facebook Reddit Mixx del.icio.us Google Live NewsVine

14 Comment(s)

  1. João Amaro on May 14, 2008 | Reply

    How can you rum make not using ./configure ?

  2. Fabrizio Balliano on May 14, 2008 | Reply

    @João Amaro: ’cause there’s no need to configure anything :-)

  3. Helder on Nov 18, 2008 | Reply

    Ola,

    Muito bom seu artigo.

    Como fazer para instalar usando o instatclient em vez de instalar o banco completo ?

    Grato,
    Helder

  4. Isidro on Jan 31, 2009 | Reply

    Hola!

    Tus indicaciones perfectas.

    Yo he intentado activar el módulo pdo_oci pero para Ubuntu 64 no funciona :(

    He “googleado” pero no he encontrado nada al respecto.

    Así que me he tenido, que instalar la versión completa oracle 10g para x86_64 y así he podido compilar la extensión para PHP. Ya funciona o eso parece ;)

    Un saludo

    Isidro

  5. PGBigot on Jul 13, 2009 | Reply

    god damn it must be nice to have a system where there already is an ORACLE_HOME with the right stuff in it. creating ORACLE_HOME and finding the right magical brew of shit to put in there is 99% of the difficulty of compiling this heap of utter shit.

  6. THanassis Bakalidis on Oct 7, 2009 | Reply

    Hi, I have followed your instructions and was able to install PDO_OCI on Fedora 11. Only difference was that ln -s /usr/include/php5/ include/php should be changed to ln -s /usr/include/php/ include/php and also I had to run configure. Otherwise there is no make file.

    Anyway everything worked after that so thanks for posting.

  7. Fabrizio Balliano on Oct 7, 2009 | Reply

    @THanassis Bakalidis: thanks for your feedback, maybe the updated guide (http://fabrizioballiano.net/2009/09/22/how-to-install-php-pdo_oci-on-ubuntu-jaunty/) already has the “ln” thing :-)

    bye!
    fabrizio

  8. DRAKUND on Sep 20, 2011 | Reply

    Bonjour, J’aime faire un mapping d’une base de donnée SQL SERVER ( microsoft) et d’une base de donnée ORACLE, il parle de PDO_OCI et PDO_SQLSRV, que je n’ai pas bien compris, Vous voulez bien m’aider a bien comprendre et a pouvoir le mettre en place , Merci d’avance

  9. Fabrizio Balliano on Sep 20, 2011 | Reply

    @DRAKUND: can you please write in english? thank you

  10. DRAKUND on Sep 20, 2011 | Reply

    Hello, I like making a mapping of a base of datum SQL SERVER ( Microsoft) and a base of datum ORACLE, he speaks about PDO_OCI and PDO_SQLSRV, whom I did not well understand, You indeed want to help me indeed has to understand(include) and must to be able to set up him(it),

    I used DEBIAN SQUEEZE
    Thank you in advance

  11. DRAKUND on Sep 21, 2011 | Reply

    Hello, I like making a mapping of a base of datum SQL SERVER ( Microsoft) and a base of datum ORACLE, he speaks about PDO_OCI and PDO_SQLSRV, whom I did not well understand, You indeed want to help me indeed has to understand(include) and must to be able to set up him(it),
    I used DEBIAN SQUEEZE
    Thank you in advance (@Fabrizio Balliano)

  12. Igor Santos on Nov 14, 2011 | Reply

    I’ve tried it in my Ubuntu 11.04 but if I try to run make without configure first it says “make: *** No targets specified and no makefile found. Stop.”

  13. Igor Santos on Nov 14, 2011 | Reply

    I’ve noticed now that there’s an updated guide.
    How about editing this post to make it clear? :P

  14. Fabrizio Balliano on Nov 14, 2011 | Reply

    @ Igor Santos: done

Post a Comment