Skip to content

Instantly share code, notes, and snippets.

@dafi
Forked from gido/macosx-install-php-oracle-oci8.md
Last active January 4, 2016 02:39
Show Gist options
  • Save dafi/8556869 to your computer and use it in GitHub Desktop.
Save dafi/8556869 to your computer and use it in GitHub Desktop.

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

Remove symlinks

find /usr/local/include -lname '*instantclient*' -exec rm {} \;

The symlinks can break the oci8 installation, if this happens remove the link to ldap.h

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

Configure tnsnames.ora

The file must be copied to /usr/local/instantclient/11.2.0.3/Network/Admin/tnsnames.ora

Install extension with pecl

Should be necessary to install autoconf

brew install autoconf

then

   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

Configure Apache

sudo vi /private/etc/apache2/httpd.conf 

Append the following lines

AddType application/x-httpd-php .php
LoadModule php5_module    /usr/local/opt/php54/libexec/apache2/libphp5.so

Restart your HTTP Server and test.

Enjoy (or try to...) !

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