Installing PDO_OCI and OCI8 PHP extensions on CentOS 6.4 64bit

I am currently working on a PHP project that requires using an Oracle server as the database. I tried setting up the Oracle PHP extensions directly on my development machine (MacOSX) but failed after a few tries. I also managed to ruin my Homebrew-PHP setup which brought me more joy.
So I ended up using Vagrant which is what I should have done in the first place. So I booted up a Vagrant box with CentOS 6.4 64bit.
This tutorial assumes that you have already installed php and other packages (e.g. php-pdo) you normally need. This was also tested with an installation of Oracle 11g Express. I’m not sure if this will work for higher versions.

Dependencies

Oracle

Installing Oracle is easy. You can follow this tutorial by David Ghedini in installing Oracle 11g Express.

Development packages

$ sudo yum install php-pear php-devel zlib zlib-devel bc libaio glibc
$ sudo yum groupinstall "Development Tools"

InstantClient

Download Oracle InstantClient RPM files here. Put these files in your server. Download the basic and devel packages.
  • Basic: oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
  • Devel: oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
Install the downloaded rpm files:
$ sudo rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
$ sudo ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11 .2/client
-s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client
$ sudo ln
Create a file inside /etc/profile.d named oracle.sh and put this as the content:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
And run it so we’ll have LD_LIBRARY_PATH as an environment variable.
source /etc/profile.d/oracle.sh

PDO_OCI

Download the PDO_OCI source using pecl.
$ pecl download PDO_OCI
$ tar -xvf PDO_OCI-1.0.tgz
$ cd PDO_OCI-1.0
Inside the PDO_OCI-1.0 folder, edit the file named config.m4.
Find a pattern like this near line 10 and add these 2 lines:
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then
PDO_OCI_VERSION=11.2
Find a pattern like this near line 101 and add these lines:
11.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;
Build and install the extension.
$ phpize
$ ./configure --with-pdo-oci=instantclient,/usr,11.2
$ make
make install
$ sudo
To enable the extension, add a file named pdo_oci.ini under /etc/php.d and put this as the content:
extension=pdo_oci.so
Validate that it was successfully installed.
$ php -i | grep oci
You should see something like this in the output:
/etc/php.d/pdo_oci.ini,
PDO drivers => oci, odbc, sqlite

OCI8

Download the OCI8 source using pear
$ pear download pecl/oci8
$ tar -xvf oci8-1.4.9.tgz
$ cd oci8-1.4.9
Build and install the extension.
$ phpize
$ ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
$ make
make install
$ sudo
To enable the extension, add a file named oci8.ini in /etc/php.d with this content:
extension=oci8.so
Validate that it was successfully installed.
$ php -i | grep oci8
You should see something like this:
/etc/php.d/oci8.ini,
oci8
connection_class => no value => no value oci8
oci8 ..default_prefetch => 100 => 100
x_persistent => -1 => -1
oci8.events => Off => Off oci8.m aoci8.old_oci_close_semantics => Off => Off
g_interval => 60 => 60 oci8.privile
oci8.persistent_timeout => -1 => -1 oci8.pi nged_connect => Off => Off
> 20 => 20
oci8.statement_cache_size =

Finishing up

Do not forget to restart your web server (e.g. Apache). You can double check with phpinfo() if the extensions were successfully installed.
This tutorial wouldn’t have been possible without these references:
Source :http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/

Posting Komentar