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

14 thoughts on “How to install PHP PDO_OCI on Ubuntu Gutsy

  1. Helder

    Ola,

    Muito bom seu artigo.

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

    Grato,
    Helder

  2. Isidro

    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

  3. PGBigot

    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.

  4. THanassis Bakalidis

    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.

  5. DRAKUND

    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

  6. DRAKUND

    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

  7. DRAKUND

    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)

  8. Igor Santos

    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.”

Leave a Reply

Your email address will not be published. Required fields are marked *