Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save krisanalfa/09b765bb95012cd36fbd to your computer and use it in GitHub Desktop.
Save krisanalfa/09b765bb95012cd36fbd 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.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!

@chanoktrue
Copy link

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
Copy link

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
Copy link

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
Copy link

That's not working for me

pecl

i already updgrad autoconf

any idea ??

@aortegae
Copy link

Captura de Pantalla 2020-03-09 a la(s) 20 30 32

Any idea??

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