You are on page 1of 5

Tomas Serrano Escamilla: OCI Driver installation on MAC 20/07/18 17(26

Lainnya Buat Blog Masuk

Tomas Serrano Escamilla


martes, 9 de septiembre de 2014 Archivo del blog

► 2018 (2)
OCI Driver installation on MAC ► 2015 (2)
▼ 2014 (7)
► diciembre (1)
▼ septiembre (2)
NODE JS.
My current project involves using PHP with an Oracle database. Oracle apparently embraces PHP
warmly and as such supports an open source database driver for the environment called OCI8. As OCI Driver installation on MAC
a Mac user I was looking to use OS X's built-in Apache and PHP setup, which like many PHP
► agosto (1)
installations does not have the Oracle OCI8 driver installed or enabled. It took me some time and
► junio (1)
research to get it up and running. I was using Oracle Express, a limited capability, free-ish version
of Oracle's database. Oracle Express was installed on a separate Windows machine as it cannot ► marzo (1)
run or be installed on Snow Leopard. I also assume that you enabled PHP in your Apache ► enero (1)
configuration (/etc/apache2/httpd.conf) and have a /etc/php.ini by copying it
► 2013 (2)
from/etc/php.ini.default.

Datos personales
OCI8 relies on OS X having several client libraries and tools from Oracle installed on OS X. For
most intents and purposes download the 64-bit version of the following files under the title "Version
10.2.0.4 (64-bit)":

instantclient-basic-10.2.0.4.0-macosx-x64.zip
instantclient-sqlplus-10.2.0.4.0-macosx-x64.zip Tomás Serrano Escamilla
instantclient-sdk-10.2.0.4.0-macosx-x64.zip
Ver todo mi perfil

Registration is required for all downloads.

Once downloaded, unzip all three files, which will look like this on your file system

Now, create a separate directory (which I called instantclient_10_2) and copy the contents of
all the files included in these subfolders into it, which will look something like this:

http://tomytree22.blogspot.com/2014/09/oci-driver-installation-on-mac.html Page 1 of 5
Tomas Serrano Escamilla: OCI Driver installation on MAC 20/07/18 17(26

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_10_2/sdk/include/*.h /usr/include

sudo cp instantclient_10_2/sqlplus /usr/bin

sudo cp instantclient_10_2/*.dylib /usr/lib

sudo cp instantclient_10_2/*.dylib.* /usr/lib

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

sudo ln -s libclntsh.dylib.10.1 libclntsh.dylib

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

You now have the Oracle tools installed. Now, to install OCI8, which we will install from the PECL
repository. In a terminal window enter

sudo pecl install oci8

[If you see an error here, you may not have Pecl or Pear (PHP package managers) installed. In
that case look at these installation instructions]

OCI8 will download and will eventually give you the prompt:

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] :

In response enter:

instantclient,/usr/lib

We are doing this because Oracle is not installed on our local machine. If it were we would respond
with the path to Oracle's installation directory. Once entered, PECL will compile and build OCI8.
Once done, it will ask you to enable the extension in your PHP configuration. To do that,
open php.ini and add the line (normally among the list of extensions):

extension=oci8.so

http://tomytree22.blogspot.com/2014/09/oci-driver-installation-on-mac.html Page 2 of 5
Tomas Serrano Escamilla: OCI Driver installation on MAC 20/07/18 17(26

Once done, you can start Apache again using

sudo apachectl start

To test the installation, enable the HR account in your Oracle installation and run a PHP file such
as (make sure you replace the password and database server IP or name in the code):

1 < ?php
2 $c = oci_connect(&#39;hr&#39;, <password here="">, &#39;<server ip="" name="" or="">/XE&#39;);
3 $s = oci_parse($c, &#39;select city, postal_code from locations&#39;);
4 oci_execute($s);
5 print &#39;&#39;;
6 while ($row = oci_fetch_array($s, OCI_NUM+OCI_RETURN_NULLS)) {
7 print &#39;&#39;;
8 foreach ($row as $item)
9 print &#39;&#39;;
10 print &#39;&#39;;
11 }
12 print &#39;
13 <table border="&quot;1&quot;">
14 <tbody>
15 <tr>
16 <td>&#39;.htmlentities($item).&#39;</td>
17 </tr>
18 </tbody>
19 </table>
20 &#39;;
21 oci_free_statement($s);
22 ?&gt;
23 </server></password>

I’m currently working on a project that requires data from a student information system
(PowerSchool). PowerSchool uses an Oracle database for it’s data layer so it became
necessary to install the oci8 extension for my local development environment. Google didn’t
provide much in terms of start to finish steps, so I thought I’d detail my steps here to
hopefully help someone else save some time.

My current local environment includes:

OS 10.9.2 (Mavericks)
MAMP Pro 3.0.5 (PHP Version 5.5.10)
Xcode (with command line tools) *required

We’re going to use PECL to install the extension.

To build the oci8 extension, you need the Oracle Instant Client Package -Basic and
SDK. Both of these can be downloaded here:
http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html

Note: The downloads are platform specific. The above link is for the Mac OS X (Intel x86). I
downloaded Version 11.2.0.4.0 (64-bit)

You also need to download php for building the extension. Download here:
http://php.net/downloads.php

Note: Download the version pertinent to your MAMP installation. I will use 5.5.10 for the
purposes of this article.

Extract php:

tar zxf ~/Downloads/php-5.5.10.tar.bz2

Install the php source into MAMP:

mkdir /Applications/MAMP/bin/php/php5.5.10/include
mv ~/Downloads/php-5.5.10 /Applications/MAMP/bin/php/php5.5.10/include/php

Run configure to generate appropriate header files:

cd /Applications/MAMP/bin/php/php5.5.10/include/php
./configure --without-iconv

Extract the instantclient-basic zip file (instantclient-basic-macos.x64-


11.2.0.4.0.zip):

unzip ~/Downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip

http://tomytree22.blogspot.com/2014/09/oci-driver-installation-on-mac.html Page 3 of 5
Tomas Serrano Escamilla: OCI Driver installation on MAC 20/07/18 17(26

Move the extracted folder, instantclient_11_2 to MAMP:

mv ~/Downloads/instantclient_11_2 /Applications/MAMP/bin/php/php5.5.10/lib/p
hp/

Extract the instantclient-sdk zip file (instantclient-sdk-macos.x64-11.2.0.4.0.zip):

unzip ~/Downloads/instantclient-sdk-macos.x64-11.2.0.4.0.zip

Move the sdk folder inside the instantclient_11_2 we moved earlier:

mv ~/Downloads/instantclient_11_2/sdk /Applications/MAMP/bin/php/php5.5.10/l
ib/php/instantclient_11_2/

Create a symbolic link to the library:

cd /Applications/MAMP/bin/php/php5.5.10/lib/php/instantclient_11_2
ln -sf libclntsh.dylib.11.1 libclntsh.dylib

BREW INSTALL AUTOCONF (if phpize failed)

Use PECL to build and install the oci8 module:

cd /Applications/MAMP/bin/php/php5.5.10/bin/
./pecl install oci8

During the installation process, it will ask for the ORACLE_HOME path. Use the
following line:

instantclient,/Applications/MAMP/bin/php/php5.5.10/lib/php/instantclient_11_2

The build process should continue and end with something like:

...
Installing '/Applications/MAMP/bin/php/php5.5.10/lib/php/extensions/no-debug
-non-zts-20121212/oci8.so'
install ok: channel://pecl.php.net/oci8-2.0.8
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini

The instantclient library has some hardcoded paths we need to take care of:

sudo mkdir -p /ade/b/3071542110/oracle/rdbms/lib/


sudo ln -sf /Applications/MAMP/bin/php/php5.5.10/lib/php/instantclient_11_2/
libclntsh.dylib.11.1 /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
sudo mkdir -p /ade/dosulliv_ldapmac/oracle/ldap/lib/
sudo ln -sf /Applications/MAMP/bin/php/php5.5.10/lib/php/instantclient_11_2/
libnnz11.dylib /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib

We also need to update the DYLD_LIBRARY_PATH for MAMP.

Edit /Applications/MAMP/Library/bin/envvars with your favorite editor:

nano /Applications/MAMP/Library/bin/envvars

Add the following line just before “export DYLD_LIBRARY_PATH”:

DYLD_LIBRARY_PATH="/Applications/MAMP/bin/php/php5.5.10/lib/php/instantclien
t_11_2:$DYLD_LIBRARY_PATH"

Finally, in MAMP, we need to tell php to load the oci8 extension per the instructions in the
build.

In MAMP, choose File -> Edit Template -> PHP -> PHP 5.5.10 php.ini

Find the section titled “Extensions”, add:

extension=oci8.so

Save the file and restart MAMP Pro. You should now be able to use the oci extension in your
php project!

Publicado por Tomás Serrano Escamilla en 9:32

1 comentario:

Unknown 8 de mayo de 2016, 20:23

Thanks! I managed to install OCI on my MAMP thanks to you! (I used MAMP, not MAMP Pro).
Thanks a lot! Tomytree22! :)
Responder

Añadir comentario

http://tomytree22.blogspot.com/2014/09/oci-driver-installation-on-mac.html Page 4 of 5
Tomas Serrano Escamilla: OCI Driver installation on MAC 20/07/18 17(26

Introduce tu comentario...

Comentar como: Cuenta de Google

Publicar Vista previa

Entrada más reciente Página principal Entrada antigua

Suscribirse a: Enviar comentarios (Atom)

Tema Sencillo. Con la tecnología de Blogger.

http://tomytree22.blogspot.com/2014/09/oci-driver-installation-on-mac.html Page 5 of 5

You might also like