Skip to content

Instantly share code, notes, and snippets.

@gido
Last active June 1, 2021 08:49
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save gido/5237100 to your computer and use it in GitHub Desktop.
Save gido/5237100 to your computer and use it in GitHub Desktop.
install Oracle PHP Extension (oracle OCI8) - instantclient for Mac OS 10.8 - homebrew environnement

Installation

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

PHP 5.4 installed with Homebrew.

Update: I wrote a blog post about this.

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.3/. 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

   ln -s /usr/local/instantclient/11.2.0.3/sdk/include/*.h /usr/local/include/
   ln -s /usr/local/instantclient/11.2.0.3/sqlplus /usr/local/bin/
   ln -s /usr/local/instantclient/11.2.0.3/*.dylib /usr/local/lib/
   ln -s /usr/local/instantclient/11.2.0.3/*.dylib.11.1 /usr/local/lib/
   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.

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

Install extension with pecl

   pecl install oci8

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

instantclient,/usr/local/lib

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.

Enjoy (or try to...) !

@XavRsl
Copy link

XavRsl commented May 13, 2016

Hi,
Just a note for my futur self (and others). If using only php (no nginx or httpd), you may add env vars to php plist file, adding them to php-fpm.conf doesn't seem to work. Here's how :

file ~/Library/LaunchAgents/homebrew.mxcl.php70.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>homebrew.mxcl.php70</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/php70/sbin/php-fpm</string>
    <string>--fpm-config</string>
    <string>/usr/local/etc/php/7.0/php-fpm.conf</string>
  </array>
  <key>EnvironmentVariables</key>
  <dict>
    <key>DYLD_LIBRARY_PATH</key>
    <string>/opt/oracle/instantclient_11_2</string>
    <key>LD_LIBRARY_PATH</key>
    <string>/opt/oracle/instantclient_11_2</string>
  </dict>
  <key>RunAtLoad</key>
  <true/>
  <key>LaunchOnlyOnce</key>
  <true/>
  <key>UserName</key>
  <string>roussel</string>
  <key>WorkingDirectory</key>
  <string>/usr/local/var</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/opt/php70/var/log/php-fpm.log</string>
</dict>
</plist>

This is how you would make Oracle DB work with Laravel Valet that uses php server capabilities on a php-fpm brew install.

Xavier

@jalex19100
Copy link

You do not need to edit the plist to add environment variables to Apache. Use "SetEnv ORACLE_HOME ..." in the httpd.conf. Trying to work around SIP isn't even necessary.

@rafaelgrube
Copy link

I tried the test from sqlplus, but always I received the ERROR: ORA-21561: OID generation failed. I looked on the internet and most of people said this is a problem with my hosts file. But I tried with IP and a received the same error. Any tip for this?

/usr/local/bin/sqlplus user/password@172.16.1.10:1521/DATABASE

@mrbrownisintown
Copy link

I've installed oracle instant client on El Capitan and am up and running, but it took me quite a part of the day...

For oracle instant client version 12.1.0.2 on El Capitan, the symlinks are slightly different:

sudo mkdir /usr/local/instantclient
sudo mkdir /usr/local/instantclient/12.1.0.2
sudo ln -s /usr/local/instantclient/12.1.0.2/sdk/include/*.h /usr/local/include/
sudo ln -s /usr/local/instantclient/12.1.0.2/sqlplus /usr/local/bin/
sudo ln -s /usr/local/instantclient/12.1.0.2/*.dylib /usr/local/lib/
sudo ln -s /usr/local/instantclient/12.1.0.2/*.dylib.12.1 /usr/local/lib/
sudo ln -s /usr/local/lib/libclntsh.dylib.12.1 /usr/local/lib/libclntsh.dylib

A couple things I've found:

sudo pecl install -f oci8-2.0.11

  • phpize didn't seem to work, check below how to check this (it didn't show PHP Api version etc), so I had to install/update xcode command line: xcode-select --install

running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:

@andreecy
Copy link

thaaank you so much! work for me on Sierra

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