Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install OCI8 and / or PDO_OCI on OSX via Brew

Installation

This procedure is tested on Mac OS X 10.10.5 with Developpers tools installed (xCode).

PHP 5.6 installed with Homebrew.

Preparation

Download the following files from Oracle website (yes, you need to create an account and accept terms):

Create and unzip all theses files into a the directory /usr/local/instantclient/11.2.0.4/. This directory will looks like:

.
├── BASIC_README
├── SQLPLUS_README
├── adrci
├── genezi
├── glogin.sql
├── libclntsh.dylib.11.1
├── libnnz11.dylib
├── libocci.dylib.11.1
├── libociei.dylib
├── libocijdbc11.dylib
├── libsqlplus.dylib
├── libsqlplusic.dylib
├── ojdbc5.jar
├── ojdbc6.jar
├── sdk
│   ├── SDK_README
│   ├── demo
│   ├── include
│   ├── ott
│   └── ottclasses.zip
├── sqlplus
├── uidrvci
└── xstreams.jar

Create symlinks

sudo ln -s /usr/local/instantclient/11.2.0.4/sdk/include/*.h /usr/local/include/
sudo ln -s /usr/local/instantclient/11.2.0.4/sqlplus /usr/local/bin/
sudo ln -s /usr/local/instantclient/11.2.0.4/*.dylib /usr/local/lib/
sudo ln -s /usr/local/instantclient/11.2.0.4/*.dylib.11.1 /usr/local/lib/
sudo ln -s /usr/local/lib/libclntsh.dylib.11.1 /usr/local/lib/libclntsh.dylib

Test with sqlplus instantclient

I recommand to install Oracle Server with a VirtualBox VM preinstalled.

sudo /usr/local/bin/sqlplus oracle/oracle@192.168.56.101

Install extension with pecl

sudo pecl install oci8-2.0.10 # phpv5.2 - phpv5.6

sudo pecl install oci8 # phpv7

If the script prompt you to provide the path to ORACLE_HOME directory, respond with:

instantclient,/usr/local/lib

Note: If you got PECL error:

touch $(brew --prefix php52)/lib/php/.lock && chmod 0644 $(brew --prefix php52)/lib/php/.lock # phpv5.2

touch $(brew --prefix php56)/lib/php/.lock && chmod 0644 $(brew --prefix php56)/lib/php/.lock # phpv5.6

touch $(brew --prefix php70)/lib/php/.lock && chmod 0644 $(brew --prefix php70)/lib/php/.lock # phpv7

And your are done, normally pecl will automatically load the extension in your php.ini. If not, add the following line to your php.ini:

extension=oci8.so

Restart your HTTP Server and test.

To installing pdo_oci. You must do following command:

mkdir -p /usr/local/lib/oracle/11.2.0.4/client
ln -sf /usr/local/instantclient/11.2.0.4/sdk/include /usr/local/lib/oracle/11.2.0.4/client/
cd /tmp
pecl download pdo_oci
tar -xvf PDO_OCI-1.0.tgz
cd PDO_OCI-1.0

After that, download this patch and apply:

wget https://gist.githubusercontent.com/krisanalfa/e0beaa512b4677c51a7c/raw/214c36a65685c9c24102ad7b703d040a7fb60243/config.m4.patch
patch config.m4 < config.m4.patch

Also, we need to patch pdo_oci.c file:

wget https://gist.githubusercontent.com/krisanalfa/1bb09ad8f9147937bbeb/raw/b66ee62e8f4601a0f669e40a619881734787d4cd/pdo_oci.c.patch
patch pdo_oci.c < pdo_oci.c.patch

We should tell our configuration to use 11.2.0.4 version, so it will find the right version in our system.

phpize
./configure --with-pdo-oci=instantclient,/usr/local/lib,11.2.0.4

Build it and install it:

make
make install

After this open your php.ini and add this line:

extension=pdo_oci.so

Test it!

@krisanalfa

This comment has been minimized.

Show comment
Hide comment
@krisanalfa

krisanalfa Jun 25, 2014

When you upgrade your PHP version, you'll find error about ldap.h. The solution is unlink the header file in /usr/local/include/ldap.h

unlink /usr/local/include/ldap.h

And there you go 😃

Owner

krisanalfa commented Jun 25, 2014

When you upgrade your PHP version, you'll find error about ldap.h. The solution is unlink the header file in /usr/local/include/ldap.h

unlink /usr/local/include/ldap.h

And there you go 😃

@FraGoTe

This comment has been minimized.

Show comment
Hide comment
@FraGoTe

FraGoTe May 15, 2016

It is strange I am getting the following error when I try to compile PDO-OCI.:

configure: error: Oracle-OCI needed libraries not found under
configure: error: I'm too dumb to figure out where the include dir is in your instant client install

FraGoTe commented May 15, 2016

It is strange I am getting the following error when I try to compile PDO-OCI.:

configure: error: Oracle-OCI needed libraries not found under
configure: error: I'm too dumb to figure out where the include dir is in your instant client install

@mangacode

This comment has been minimized.

Show comment
Hide comment
@mangacode

mangacode Jun 17, 2016

I have still the following errors when I do $ php
dyld: lazy symbol binding failed: Symbol not found: _OCIInitialize
Referenced from: /Applications/MAMP/bin/php/php5.6.10/lib/php/extensions/no-debug-non-zts-20131226/pdo_oci.so
Expected in: flat namespace

dyld: Symbol not found: _OCIInitialize
Referenced from: /Applications/MAMP/bin/php/php5.6.10/lib/php/extensions/no-debug-non-zts-20131226/pdo_oci.so
Expected in: flat namespace

Trace/BPT trap: 5

I already downloaded the new Oracle client 12_1, installed the Xcode commandline tools, I have osx 10.11.5

Don't know what to do...

mangacode commented Jun 17, 2016

I have still the following errors when I do $ php
dyld: lazy symbol binding failed: Symbol not found: _OCIInitialize
Referenced from: /Applications/MAMP/bin/php/php5.6.10/lib/php/extensions/no-debug-non-zts-20131226/pdo_oci.so
Expected in: flat namespace

dyld: Symbol not found: _OCIInitialize
Referenced from: /Applications/MAMP/bin/php/php5.6.10/lib/php/extensions/no-debug-non-zts-20131226/pdo_oci.so
Expected in: flat namespace

Trace/BPT trap: 5

I already downloaded the new Oracle client 12_1, installed the Xcode commandline tools, I have osx 10.11.5

Don't know what to do...

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Aug 19, 2016

meet the same problem,how to solve it

It is strange I am getting the following error when I try to compile PDO-OCI.:

configure: error: Oracle-OCI needed libraries not found under
configure: error: I'm too dumb to figure out where the include dir is in your instant client install

ghost commented Aug 19, 2016

meet the same problem,how to solve it

It is strange I am getting the following error when I try to compile PDO-OCI.:

configure: error: Oracle-OCI needed libraries not found under
configure: error: I'm too dumb to figure out where the include dir is in your instant client install

@wax13003

This comment has been minimized.

Show comment
Hide comment
@wax13003

wax13003 Nov 21, 2016

solved my problem, thanks!

wax13003 commented Nov 21, 2016

solved my problem, thanks!

@stefanlam88

This comment has been minimized.

Show comment
Hide comment
@stefanlam88

stefanlam88 Dec 15, 2016

wax13003 any solution can share?

stefanlam88 commented Dec 15, 2016

wax13003 any solution can share?

@tap52384

This comment has been minimized.

Show comment
Hide comment
@tap52384

tap52384 Dec 15, 2016

Can install at least version 2.0.12 of the PECL extension now for php56.

tap52384 commented Dec 15, 2016

Can install at least version 2.0.12 of the PECL extension now for php56.

@kaizokou

This comment has been minimized.

Show comment
Hide comment
@kaizokou

kaizokou Jan 26, 2017

@leadebug @FraGoTe how did you solve the problem, I have the same error with client 12_1

kaizokou commented Jan 26, 2017

@leadebug @FraGoTe how did you solve the problem, I have the same error with client 12_1

@kaizokou

This comment has been minimized.

Show comment
Hide comment
@kaizokou

kaizokou Jan 26, 2017

configure: error: Unsupported Oracle version! 12.1

I had to edit the configure file and add the 12.1 version. It's around line 5069

case clntsh in
 c|c_r|pthread*) ;;
 *)
   if test "$ext_shared" = "yes"; then
       PDO_OCI_SHARED_LIBADD="$PDO_OCI_SHARED_LIBADD -lclntsh"
   else


 case clntsh in
 c|c_r|pthread*) ;;
 *)
     LIBS="$LIBS -lclntsh"
   ;;
 esac


   fi
   ;;
 esac


     ;;
   12.1)    

kaizokou commented Jan 26, 2017

configure: error: Unsupported Oracle version! 12.1

I had to edit the configure file and add the 12.1 version. It's around line 5069

case clntsh in
 c|c_r|pthread*) ;;
 *)
   if test "$ext_shared" = "yes"; then
       PDO_OCI_SHARED_LIBADD="$PDO_OCI_SHARED_LIBADD -lclntsh"
   else


 case clntsh in
 c|c_r|pthread*) ;;
 *)
     LIBS="$LIBS -lclntsh"
   ;;
 esac


   fi
   ;;
 esac


     ;;
   12.1)    
@reekoheek

This comment has been minimized.

Show comment
Hide comment
@reekoheek

reekoheek Mar 3, 2017

I got this issue

$ ORACLE_HOME="instantclient,/usr/local/instantclient/12.1.0.2.0,12.1" brew install php71 --with-pdo-oci --with-pear --without-fpm
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
mercurial

==> Installing php71 from homebrew/php
==> Downloading https://php.net/get/php-7.1.2.tar.bz2/from/this/mirror
Already downloaded: /Users/jafar/Library/Caches/Homebrew/php71-7.1.2
==> ./configure --prefix=/usr/local/Cellar/php71/7.1.2_13 --localstatedir=/usr/local/var --sysconfdir=/usr/local
==> make
Last 15 lines from /Users/jafar/Library/Logs/Homebrew/php71/02.make:
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:597:23: error: use of undeclared identifier 'LDAP_OPT_X_SASL_AUTHCID'
                ldap_get_option(ld, LDAP_OPT_X_SASL_AUTHCID, &ctx->authcid);
                                    ^
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:600:23: error: use of undeclared identifier 'LDAP_OPT_X_SASL_AUTHZID'
                ldap_get_option(ld, LDAP_OPT_X_SASL_AUTHZID, &ctx->authzid);
                                    ^
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:680:29: error: use of undeclared identifier 'LDAP_OPT_X_SASL_SECPROPS'
                ldap_set_option(ld->link, LDAP_OPT_X_SASL_SECPROPS, props);
                                          ^
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:683:77: error: use of undeclared identifier 'LDAP_SASL_QUIET'
        rc = ldap_sasl_interactive_bind_s(ld->link, binddn, ctx->mech, NULL, NULL, LDAP_SASL_QUIET, _php_sasl_interact, ctx);
                                                                                   ^
14 errors generated.
make: *** [ext/ldap/ldap.lo] Error 1
make: *** Waiting for unfinished jobs....

READ THIS: http://docs.brew.sh/Troubleshooting.html

These open issues may also help:
php71-stemmer https://github.com/Homebrew/homebrew-php/pull/3630
php71 does not work with httpd https://github.com/Homebrew/homebrew-php/issues/3960
brew install php71-mcrypt failed. https://github.com/Homebrew/homebrew-php/issues/3589

and after i unlinked ldap.h the error is still the same :(

reekoheek commented Mar 3, 2017

I got this issue

$ ORACLE_HOME="instantclient,/usr/local/instantclient/12.1.0.2.0,12.1" brew install php71 --with-pdo-oci --with-pear --without-fpm
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
mercurial

==> Installing php71 from homebrew/php
==> Downloading https://php.net/get/php-7.1.2.tar.bz2/from/this/mirror
Already downloaded: /Users/jafar/Library/Caches/Homebrew/php71-7.1.2
==> ./configure --prefix=/usr/local/Cellar/php71/7.1.2_13 --localstatedir=/usr/local/var --sysconfdir=/usr/local
==> make
Last 15 lines from /Users/jafar/Library/Logs/Homebrew/php71/02.make:
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:597:23: error: use of undeclared identifier 'LDAP_OPT_X_SASL_AUTHCID'
                ldap_get_option(ld, LDAP_OPT_X_SASL_AUTHCID, &ctx->authcid);
                                    ^
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:600:23: error: use of undeclared identifier 'LDAP_OPT_X_SASL_AUTHZID'
                ldap_get_option(ld, LDAP_OPT_X_SASL_AUTHZID, &ctx->authzid);
                                    ^
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:680:29: error: use of undeclared identifier 'LDAP_OPT_X_SASL_SECPROPS'
                ldap_set_option(ld->link, LDAP_OPT_X_SASL_SECPROPS, props);
                                          ^
/private/tmp/php71-20170303-86632-r5c8bn/php-7.1.2/ext/ldap/ldap.c:683:77: error: use of undeclared identifier 'LDAP_SASL_QUIET'
        rc = ldap_sasl_interactive_bind_s(ld->link, binddn, ctx->mech, NULL, NULL, LDAP_SASL_QUIET, _php_sasl_interact, ctx);
                                                                                   ^
14 errors generated.
make: *** [ext/ldap/ldap.lo] Error 1
make: *** Waiting for unfinished jobs....

READ THIS: http://docs.brew.sh/Troubleshooting.html

These open issues may also help:
php71-stemmer https://github.com/Homebrew/homebrew-php/pull/3630
php71 does not work with httpd https://github.com/Homebrew/homebrew-php/issues/3960
brew install php71-mcrypt failed. https://github.com/Homebrew/homebrew-php/issues/3589

and after i unlinked ldap.h the error is still the same :(

@chanoktrue

This comment has been minimized.

Show comment
Hide comment
@chanoktrue

chanoktrue Aug 14, 2017

i have error below.

Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20131226/oci8.so'
ERROR: failed to write /usr/lib/php/extensions/no-debug-non-zts-20131226/oci8.so (copy(/usr/lib/php/extensions/no-debug-non-zts-20131226/oci8.so): failed to open stream: Operation not permitted)
---> fixed
1.restart
2.cmd+r
3.terminal
4.csrutil disable

chanoktrue commented Aug 14, 2017

i have error below.

Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20131226/oci8.so'
ERROR: failed to write /usr/lib/php/extensions/no-debug-non-zts-20131226/oci8.so (copy(/usr/lib/php/extensions/no-debug-non-zts-20131226/oci8.so): failed to open stream: Operation not permitted)
---> fixed
1.restart
2.cmd+r
3.terminal
4.csrutil disable

@alexbonhomme

This comment has been minimized.

Show comment
Hide comment
@alexbonhomme

alexbonhomme Sep 12, 2017

Hey guys, I updated this nice tutorial with the last version of OCI8 (12.1) here : https://gist.github.com/alexbonhomme/0d5976f2126bcde34b817e0143be0dff
(with the fix of @kaizokou)

alexbonhomme commented Sep 12, 2017

Hey guys, I updated this nice tutorial with the last version of OCI8 (12.1) here : https://gist.github.com/alexbonhomme/0d5976f2126bcde34b817e0143be0dff
(with the fix of @kaizokou)

@arsenanai

This comment has been minimized.

Show comment
Hide comment
@arsenanai

arsenanai Dec 14, 2017

Hello, @krisanalfa, you are creating symlinks just to feet PDO_OCI's config.m4 file statements? Could you explain please, the reason why did you unzipped instantclient to /usr/local folder? I tried as you explained, but with no success.

arsenanai commented Dec 14, 2017

Hello, @krisanalfa, you are creating symlinks just to feet PDO_OCI's config.m4 file statements? Could you explain please, the reason why did you unzipped instantclient to /usr/local folder? I tried as you explained, but with no success.

@kamalkech

This comment has been minimized.

Show comment
Hide comment
@kamalkech

kamalkech May 20, 2018

That's not working for me

pecl

i already updgrad autoconf

any idea ??

kamalkech commented May 20, 2018

That's not working for me

pecl

i already updgrad autoconf

any idea ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment