The following may be very useful if you are using a Mac OS X Web Server to host a PHP based CMS/LMS such as Moodle, have an Oracle database containing student records such as PowerSchool and wanted to integrate them together for automatic course creation and student enrolment in Moodle. Tested with Mac OS 10.6.7 Server, Developer Tools 3.2.5, Oracle Instant Client 10.2.0.4.0 64-bit

Configure a Mac OS X Web Server to access a Oracle database using the default bundled PHP install, Oracle’s Instant Client and the Oci8 PHP extension in 5 simple steps:

Step 1 – Download and install the Apple Developer Tools (free version 3.2.5 or paid version 4) from the Mac Dev Center (free account required) or from the Mac App Store (paid)

Step 2 – Download Instant Client from www.oracle.com (you must create a free account and accept the license before downloading)

  • Instant Client Package – Basic
  • Instant Client Package – SQL*Plus
  • Instant Client Package – SDK

Unzip and copy all contents to a system location (/usr/local/oracle/instantclient), change ownership and permissions to root:wheel -rwxr-xr-x

Step 3 – Using pecl download and install the oci8 PHP extension, in Terminal run…

sudo pecl install oci8

When you recieve the following prompt type ‘instantclient’, (comma) followed by the full path to your instantclient directory (i.e /usr/local/oracle/instantclient) …

Please provide the path to the ORACLE_HOME directory.
Use 'instantclient,/path/to/instant/client/lib' if
you're compiling with Oracle Instant Client [autodetect] :
instantclient,/usr/local/oracle/instantclient

After the extension is installed here ‘/usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so’, add the following line to /etc/php.ini to enable the oci8 extension and restart apache…

extension=oci8.so

Step 4 – Now add the following environment variable to any bash php scripts that call oci8 or launchd to make it available to apache web server

bash

export DYLD_LIBRARY_PATH=/usr/local/oracle/instantclient

/etc/launchd.conf

setenv DYLD_LIBRARY_PATH /usr/local/oracle/instantclient

Step 5 – Test it! (Replace dbuser, dbpass, db.server.edu and SID with the connection string to your database server)

<?php

// Print DYLD_LIBRARY_PATH environment variable
echo "DYLD_LIBRARY_PATH = " .getenv('DYLD_LIBRARY_PATH') . "\n";

// Create an oci connection
$c = oci_connect('dbuser', 'dbpass', '//db.server.edu/SID', utf-8); 

// Get Oracle database server version
echo "Server Version: " . oci_server_version($c) . " - ";

// Echo out what should be an Oracle resource
print_r($c); 

if (!$c) {
	$m = oci_error();
	echo $m["message"];
	exit;
}

?>

And you should see something like this…

DYLD_LIBRARY_PATH = /usr/local/oracle/instantclient
Server Version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
64bit Production With the Partitioning, OLAP and Data Mining options - Resource id #3
Advertisements