Special thanks to:
-
Download Instant Client from http://www.oracle.com/technetwork/indexes/downloads/index.html#database (you must be registered in Oracle; it's free). You will need
instantclient-basic-*-*.zip
andinstantclient-sdk-*-*.zip
files. -
Execute the following commands in your terminal:
$ sudo su - $ mkdir -p /opt/oracle/instantclient $ cd /opt/oracle/instantclient
-
Copy downloaded files into
/opt/oracle/instantclient
. -
Unzip files executing these commands:
$ unzip instantclient-basic-*-*.zip $ unzip instantclient-sdk-*-*.zip
-
Move all
/opt/oracle/instantclient/instantclient
content to/opt/oracle/instantclient
:$ mv instantclient*/* ./ $ rmdir instantclient*/
-
During extension compiling, some errors will arise when linking with some libraries. To avoid them, do:
$ ln -s libclntsh.so.* libclntsh.so $ ln -s libocci.so.* libocci.so $ echo /opt/oracle/instantclient >> /etc/ld.so.conf $ ldconfig
-
Create a folder for your network configuration files:
$ mkdir -p network/admin
-
Place
sqlnet.ora
andtnsnames.ora
files in/opt/oracle/instantclient/network/admin
.
Now you have the basic connection kit for connections and SDK for compiling PHP extensions.
-
Get all essential packages for download and compiling from PEAR repositories:
$ apt-get install --yes php5 php5-cli php5-dev php-db php-pear $ apt-get install --yes build-essential libaio1
-
Request OCI8 install:
$ pecl install oci8
Type
instantclient,/opt/oracle/instantclient
when prompted for Instant Client path. -
Save this text in
/etc/php5/mods-available/oci8.ini
:extension=oci8.so
-
Activate extension:
$ php5enmod oci8
Now you have all oci_*
functions available for PHP in both php-cli and Apache.
The pdo_oci
library is outdated, so its install is more tricky.
-
Fix paths:
$ cd /usr/include/ $ ln -s php5 php $ cd /opt/oracle/instantclient $ mkdir -p include/oracle/11.1/ $ cd include/oracle/11.1/ $ ln -s ../../../sdk/include client $ cd - $ mkdir -p lib/oracle/11.1/client $ cd lib/oracle/11.1/client $ ln -s ../../../../ lib $ cd -
-
Download
pdo_oci
viapecl
:$ pecl channel-update pear.php.net $ mkdir -p /tmp/pear/download/ $ cd /tmp/pear/download/ $ pecl download pdo_oci
-
Extract source:
$ tar xvf PDO_OCI*.tgz $ cd PDO_OCI*
-
Create a file named
config.m4.patch
:*** config.m4 2005-09-24 17:23:24.000000000 -0600 --- /home/myuser/Desktop/PDO_OCI-1.0/config.m4 2009-07-07 17:32:14.000000000 -0600 *************** *** 7,12 **** --- 7,14 ---- if test -s "$PDO_OCI_DIR/orainst/unix.rgs"; then PDO_OCI_VERSION=`grep '"ocommon"' $PDO_OCI_DIR/orainst/unix.rgs | sed 's/[ ][ ]*/:/g' | cut -d: -f 6 | cut -c 2-4` test -z "$PDO_OCI_VERSION" && PDO_OCI_VERSION=7.3 + elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.1; then + PDO_OCI_VERSION=11.1 elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.10.1; then PDO_OCI_VERSION=10.1 elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.9.0; then *************** *** 119,124 **** --- 121,129 ---- 10.2) PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD) ;; + 11.1) + PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD) + ;; *) AC_MSG_ERROR(Unsupported Oracle version! $PDO_OCI_VERSION) ;; #EOF
-
Apply patch:
$ patch --dry-run -i config.m4.patch && patch -i config.m4.patch && phpize
-
Replace all references of
function_entry
tozend_function_entry
inpdo_oci.c
. -
Configure, compile and install:
$ ORACLE_HOME=/opt/oracle/instantclient ./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient,11.1 $ make && make test && make install && mv modules/pdo_oci.so /usr/lib/php5/*+lfs/
-
Save this text in
/etc/php5/mods-available/pdo_oci.ini
:extension=pdo_oci.so
-
Activate extension:
$ php5enmod pdo_oci
And now you can take a cup of coffee.