Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wmfairuz/5bd5bbfc8903d2a39abfe2c570ac9503 to your computer and use it in GitHub Desktop.
Save wmfairuz/5bd5bbfc8903d2a39abfe2c570ac9503 to your computer and use it in GitHub Desktop.
Installing OCI8 module for PHP on MAC OS X

For this tutorial is based on Oracle Instant Client 11.2. Please note for correct install, we must use 64-bit version.

Oracle Instant Client Configuration

Download Instant Client from Oracle site(http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html): - Basic 64-bit - SDK 64-bit - SqlPlus 64-bit

Create the directory /opt/instantclient_11_2

    mkdir -p /opt/instantclient_11_2

Uncompress instant client modules inside directory

    tar -zxvf <file.tar>

The next step is to copy the necessary files into your OS X dynamic library and bin directories (as described here). Open a terminal window and go to the directory above the one you created containing all the files you unzipped.

sudo cp instantclient_11_2/sdk/include/*.h /usr/include
sudo cp instantclient_11_2/sqlplus /usr/bin
sudo cp instantclient_11_2/*.dylib /usr/lib
sudo cp instantclient_11_2/*.dylib.* /usr/lib

Now move to the /usr/lib directory and create the following link:

sudo ln -s libclntsh.dylib.11.1 libclntsh.dylib

To test, open another terminal window or tab, and try to run Oracle's SQLPlus tool using /usr/bin/sqlplus. If it worked, you are almost there. Exit SQLPlus by entering quit or simply Ctrl+C.

Configure OCI8 module for PHP

Download OCI8 module using pecl

    pecl download oci8-2.0.8

Uncompress OCI8

    tar -zxvf oci8-2.0.8.tar

Go to oci8 directory

    cd oci8

Run configure to generate configuration rules to compilation

phpize
./configure --with-oci8=shared,instantclient,/usr/lib/

Run make to compile and install oci8.so - sudo make all install Open php.ini and add the following line:

    extension=oci8.so

Restart apache.

Oracle test PHP

<?php
$conn = oci_connect("username", "password", "//hostname/servicename");
if (!$conn) {
   $m = oci_error();
   echo $m['message'], "\n";
   exit;
}
else {
   print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment