Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save alexbonhomme/0d5976f2126bcde34b817e0143be0dff to your computer and use it in GitHub Desktop.
Save alexbonhomme/0d5976f2126bcde34b817e0143be0dff to your computer and use it in GitHub Desktop.
Install OCI8 and / or PDO_OCI on OSX via Brew

Installation

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

PHP 5.6 installed with https://php-osx.liip.ch/.

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/12.1.0.2.0/. 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/12.1.0.2.0/sdk/include/*.h /usr/local/include/
sudo ln -s /usr/local/instantclient/12.1.0.2.0/sqlplus /usr/local/bin/
sudo ln -s /usr/local/instantclient/12.1.0.2.0/*.dylib /usr/local/lib/
sudo ln -s /usr/local/instantclient/12.1.0.2.0/*.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/12.1.0.2.0/client
ln -sf /usr/local/instantclient/12.1.0.2.0/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

And finaly, patch configure file:

wget https://gist.githubusercontent.com/alexbonhomme/415ab5565fccc5cd22a7a63dfdf2f5a1/raw/f51f46bf3584d567f057c21a95d8ab96f721d085/configure.patch
patch configure < configure.patch

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

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

Build it and install it:

make
make install

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

extension=pdo_oci.so

Test it!

@vhorky
Copy link

vhorky commented Oct 5, 2017

5 warnings and 1 error generated.
make: *** [oci_driver.lo] Error 1

/tmp/PDO_OCI-1.0/oci_driver.c:51:46: error: too many arguments to function call, expected 2, have 3

@nohnaimer
Copy link

On 12.2.0.1.0 does not work

checking if awk is broken... no
checking Oracle OCI support for PDO... yes, shared
checking Oracle Install-Dir... instantclient,/usr/local/lib,12.2.0.1.0 :instantclient,/usr/local/lib,12.2.0.1.0:
checking if that is sane... yes
checking for oci.h... /usr/local/lib/oracle/12.2.0.1.0/client/include
configure: error: Unsupported Oracle version! 12.2

@arsenanai
Copy link

Hi, @vhorky, you faced same error as I'm facing now on 10.13 version osx, have you come to some success solution?

@arsenanai
Copy link

arsenanai commented Dec 14, 2017

@nohnaimer, download patch for configure file(configure.patch), edit version to 12.2 on it and apply it file after phpize command
Also check config.m4.patch file, and set there version to 12.2

@davizanotto
Copy link

Hi @vhorky and @arsenanai, did you solved the error on make?

oci_driver.c:51:46: error: too many arguments to function call, expected 2, have 3

@davizanotto
Copy link

davizanotto commented Mar 10, 2018

[RESOLVED]

Finally I could configure successfully, doing the follow:

First of all, my enviroment is: macOS High Sierra 10.3.3 / PHP 7.1.7 (cli) / instantclient 12.1.0.2.0.

Following this tutorial above, when I was trying to make after ./configure --with-pdo-oci... I receive the error:

oci_driver.c:51:46: error: too many arguments to function call, expected 2, have 3.

The problem was that PDO_OCI-1.0 from pecl is too old.

So I downloaded the source code of PHP 7.1.15 (http://php.net/get/php-7.1.15.tar.gz/from/a/mirror), cause it has the source code of pdo_oci, and extract into ~/php-7.1.15 then:

mkdir /usr/local/lib/client64/include/
sudo ln -s /usr/local/instantclient/12.1.0.2.0/sdk/include/*.h /usr/local/lib/client64/include/

You have to create this path and link headers into cause pdo_oci/configure, by default, will try to get oci.h from this path. If you don't do this, probably you'll get the error:

checking for oci.h... configure: error: I'm too dumb to figure out where the include dir is in your Instant Client install

So, let's make pdo_oci:

cd ~/php-7.1.15/ext/pdo_oci
phpize
./configure --with-pdo-oci=instantclient,/usr/local/lib/,12.1.0.2.0
make
sudo make install

To check where is your pdo_oci.so file:

find / -name pdo_oci.so

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

extension=pdo_oci.so

That's it.

@brunoti
Copy link

brunoti commented Mar 15, 2018

@davizanotto THANKS MAN! Your way works. I was almost giving up.

@mangcoding
Copy link

mangcoding commented Mar 20, 2018

@davizanotto Thanks. i was almost giving up too

@rafaelqm
Copy link

@davizanotto deserves a trophy, thanks!

In my case I downloaded the version 7.1.16 and from that folder (/ext/pdo_oci) I ran phpize, make and make install.

@rizlantamima
Copy link

Somebody can help me please? I got this error message
Unsupported Oracle version! 12.2

how can I solve this?

@yogithesymbian
Copy link

my mac m1

Route::get('/', function () {
    dd(phpinfo());
    exit();

502 Bad Gateway
nginx/1.19.8

dunno why , cat logs there is no error .

➜  20190902 git:(stable) php -m | grep 'oci8'
oci8

i have test my oci with
composer require yajra/laravel-oci8:^7
where thats command needed oci and i can do that.

when i try phpinfo i got the 502, or oci_connect()

but when i check oci_error the response is false that's mean no error

how to solve this ?

@yogithesymbian
Copy link

i have try with oracle instant v11 , v12 , v19.8 ( latest version ) same as problem

@lcantonelli
Copy link

lcantonelli commented Nov 14, 2023

@davizanotto, your solution worked for PHP 8.2 as well. Thank you very much, I spent a long time trying to fix it

@gitipasand
Copy link

i am create a page for install oci8 in macbook m1
https://github.com/gitipasand/install-Oracle-PHP-extension-on-MAC-M1

@gitipasand
Copy link

i am create a page for install oci8 in macbook m1 https://github.com/gitipasand/install-Oracle-PHP-extension-on-MAC-M1

please star

@yogithesymbian
Copy link

i am create a page for install oci8 in macbook m1 https://github.com/gitipasand/install-Oracle-PHP-extension-on-MAC-M1

please star

nice but currently i am not longer on my project thats used oracle again. i exit from team 👀. old yers ago i just use server instead local oracle . maybe next project i will try it .

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