Special thanks to:
- AJ ONeal
- Hsiao Siyuan
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 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.
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
.
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
/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
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';
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.