Giter Site home page Giter Site logo

pdo-oci-extension's Introduction

The motherf*cking way the get Oracle database connections in PHP5 over Ubuntu, revisited

Special thanks to:

  • AJ ONeal
  • Hsiao Siyuan

Before anything

Taking risks

Long time I didn't write PHP aplications that connect to Oracle databases, implying that I'm not aware of any issues related to this procedure. You are invited to contribute with your reports and workarounds (some of them are commented here and I'll do a review ASAP).

Alongside these things, you should consider the fact you are dealing with an experimental extension. It's strongly inadvisable use it at production environment. I recommend you to see the awesome taq/pdooci.

Ubuntu and Docker

Ubuntu versions tested are 12.04 (Precise) and 14.04 (Trusty). All commands that should be performed in terminal are describe inside the precise/Dockerfile and trusty/Dockerfile files. Docker serves to the purpouse of testing procedures of compiling and install in an isolated environment. You can export the compiled extension files and even the Instant Client directory using a container mount point, though.

Download Oracle Instant Client, manually

Unfortunatelly, the Oracle Instant Client download can't be automated due license terms. That means you must be registered in Oracle (it's free) and get the ZIP files by yourself. They are instantclient-basic-linux.x64-12.1.0.2.0.zip and instantclient-sdk-linux.x64-12.1.0.2.0.zip, and should be placed inside precise/instantclient and trusty/instantclient.

1. Install build tools and dependencies

You'll need unzip, PHP itself and some essentials to compile C programs:

$ apt-get install -y unzip php5 php5-cli php5-dev php-db php-pear build-essential libaio1 re2c

Extensions makefiles will try to include *.h files from /usr/include/php, a inexistent directory. However, /usr/include/php5 contains all relevant files to compiling, so we'll link it:

$ ln -s /usr/include/php5 /usr/include/php

2. Unzip Instant Client

/opt/oracle/instantclient is the right directory for the job of containing Instant Client files.

$ mkdir -p /opt/oracle/instantclient

Unzip basic files into /opt/oracle

$ unzip instantclient-basic-linux.x64-12.1.0.2.0.zip -d /opt/oracle

It'll create /opt/oracle/instantclient_12_1 directory, that should be renamed as libraries directory:

$ mv /opt/oracle/instantclient_12_1 /opt/oracle/instantclient/lib

Same goes for SDK files:

$ unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip -d /opt/oracle
$ mv /opt/oracle/instantclient_12_1/sdk/include /opt/oracle/instantclient/include

Some libraries have an irrelevant version number that can be safely ignored:

$ ln -s /opt/oracle/instantclient/lib/libclntsh.so.12.1 /opt/oracle/instantclient/lib/libclntsh.so
$ ln -s /opt/oracle/instantclient/lib/libocci.so.12.1 /opt/oracle/instantclient/lib/libocci.so

The Oracle libraries directory must be accessible anywhere:

$ echo /opt/oracle/instantclient/lib >> /etc/ld.so.conf
$ ldconfig

3. Install the OCI8 PHP Extension

You need to download the ancient extension with the elderly PECL.

$ pecl install oci8-2.0.12

When prompted for Instant Client path, just type instantclient,/opt/oracle/instantclient/lib.

Now we should activate OCI8, differences between PHP versions in Ubuntu distros start to get in the way though.

  • Ubuntu 12.04 (Precise) / PHP 5.3.10:

    Create file /etc/php5/conf.d/oci8.ini containing just one line:

    extension=oci8.so
  • Ubuntu 14.04 (Trusty) / PHP 5.5.9:

    Create file /etc/php5/mods-available/oci8.ini containing just one line:

    extension=oci8.so

    Link it to activate on PHP CLI (command line interface):

    $ ln -s ../../mods-available/oci8.ini /etc/php5/cli/conf.d/20-oci8.ini

    If you have an Apache setup:

    $ ln -s ../../mods-available/oci8.ini /etc/php5/apache2/conf.d/20-oci8.ini

Now you have all oci_* functions available for PHP in both php-cli and Apache. Confirm it using this script:

<?php
echo function_exists('oci_connect') ? 'OCI8 active' : 'OCI8 inactive';

4. Build and install the PDO/OCI PHP Extension

The pdo_oci library is outdated, so its install is more tricky.

Download pdo_oci via pecl:

$ pecl channel-update pear.php.net
$ cd /tmp
$ pecl download pdo_oci

Extract source:

$ tar xvf PDO_OCI-1.0.tgz -C /tmp
$ cd PDO_OCI-1.0

Patch config.m4 to replace Instant Client 10.1 with 12.1;

$ sed 's/10.1/12.1/' -i /tmp/PDO_OCI-1.0/config.m4

Replace all references of function_entry to zend_function_entry in pdo_oci.c:

$ sed 's/function_entry/zend_function_entry/' -i /tmp/PDO_OCI-1.0/pdo_oci.c

Prepare and build:

$ phpize
$ ./configure --with-pdo-oci=/opt/oracle/instantclient
$ make install
  • Ubuntu 12.04 (Precise) / PHP 5.3.10:

    Create file /etc/php5/conf.d/pdo_oci.ini containing just one line:

    extension=pdo_oci.so
  • Ubuntu 14.04 (Trusty) / PHP 5.5.9:

    Create file /etc/php5/mods-available/pdo_oci.ini containing just one line:

    extension=pdo_oci.so

    Link it to activate on PHP CLI (command line interface):

    $ ln -s ../../mods-available/pdo_oci.ini /etc/php5/cli/conf.d/20-pdo_oci.ini

    If you have an Apache setup:

    $ ln -s ../../mods-available/pdo_oci.ini /etc/php5/apache2/conf.d/20-pdo_oci.ini

And now you can take a cup of coffee.

pdo-oci-extension's People

Contributors

tassoevan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.