PHP 5.2, Mac OS X Leopard and Oracle

Published on: January 16, 2009   

I wanted to give a heads-up to all the PHP, Mac and Oracle fans that I just had an article published on the Oracle Technology Network (OTN). It's been in the works for months but has only just recently been published. I have to give Christopher Jones a lot of credit for being patient wtih me. The end result was an article that was fairly easy to write but was a bit of a pain. What you see in the final version is how to setup PHP, Apache and the Oracle Instant Client on a Macbook running Leopard. The most unfortunate part of all this is I was unable to get all the moving parts working on stock version of Apache. Instead I had to roll with a version of Apache I compiled from source. For those of you interested in using Oracle the article walks you through the installation process pretty well. It should also be noted I did confirm the same instructions worked flawlessly using the last PHP 5.3 alpha release. To the skilled people in the PHP Community, if someone does figure out how to get this working with the stock version of Apache I would love to hear how you did it because that'd be ideal for most of us Mac users. Comments aren't possible on the OTN version so feel free to add comments here.

Trackback

Trackback URL for this entry: http://www.tonybibbs.com/trackback.php/php-oracle-leopard

No trackback comments for this entry.

PHP 5.2, Mac OS X Leopard and Oracle | 14 comments | Create New Account

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on January 18, 2009

 I had been struggling to load oci8 support into php and apache that comes from apple. However this fails as oci8 libraries as 32 bit.

Simple approach was to add the ORACLE ENVIRONMENT VARIABLES to be passed to apache during startup in /System/Libraries/LaunchDaemons/org.apache.httpd.plist and also run the httpd daemon in 32 bit

 

Following is my org.apache.httpd.plist content

 

<?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>EnvironmentVariables</key>

<dict>

<key>DYLD_LIBRARY_PATH</key>

<string>/usr/local/oracle/instantclient_10_2</string>

<key>LD_LIBRARY_PATH</key>

<string>/usr/local/oracle/instantclient_10_2</string>

<key>NLS_LANG</key>

<string>Japanese_Japan.AL32UTF8</string>

<key>ORACLE_BASE</key>

<string>/usr/local/oracle</string>

<key>ORACLE_HOME</key>

<string>/usr/local/oracle/client_10_2/ohome</string>

<key>ORACLE_SERVICE</key>

<string>MacBook.local</string>

<key>ORACLE_SID</key>

<string>MacBook</string>

<key>ORA_HOME</key>

<string>/usr/local/oracle</string>

<key>TNS_ADMIN</key>

<string>/usr/local/oracle/network/admin</string>

<key>TWO_TASK</key>

<string>WinMacBook</string>

</dict>

<key>Label</key>

<string>org.apache.httpd</string>

<key>OnDemand</key>

<false />

<key>ProgramArguments</key>

<array>

<string>/usr/bin/arch -i386 /usr/sbin/httpd</string>

<string>-D</string>

<string>FOREGROUND</string>

</array>

<key>SHAuthorizationRight</key>

<string>system.preferences</string>

</dict>

</plist>

 with the above settings i am able to connect to oracle instance  in my windows virtual machine.   I just stopped trying to make run php oci8 and everthing with apache 64 bit.   Hope i can spend time in developing php application now instead of figuring out how to connect to oracle in php with 64 bit apache

 

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on November 09, 2009
qOigjF ohxaosnuqszv, [url=http://mjtbiqudtbdv.com/]mjtbiqudtbdv[/url], [link=http://vecfwndusrsk.com/]vecfwndusrsk[/link], http://bewfalehnsex.com/
PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on November 15, 2009
vWnETA lpbyjaeclcku, [url=http://ytkzztrnkkwt.com/]ytkzztrnkkwt[/url], [link=http://yfptphbcrdcx.com/]yfptphbcrdcx[/link], http://pgpfjarricci.com/
PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on November 18, 2009
c43uVO pxrgrqmjyttv, [url=http://sttdptkhxfwj.com/]sttdptkhxfwj[/url], [link=http://ffwbpgctmswa.com/]ffwbpgctmswa[/link], http://ikbwwdpiuudp.com/
WoGUVwEDZrFBHZOtlF
Authored by: Anonymous on December 13, 2009
mraXoj zrpkpciogdtb, [url=http://nyicsmhrbsfp.com/]nyicsmhrbsfp[/url], [link=http://cbqryeywharv.com/]cbqryeywharv[/link], http://qoswvnrienrv.com/
PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on January 27, 2009

Hi Tony,

I don't have any Oracle instances to test this against, but I was able to compile ext/oci8 for all the architectures necessary on my Mac OS X machine. I used the 5.2.6 sources, and built ext/oci8 with the following:

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' LDFLAGS='-O3 -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64 -arch ppc7400 -arch ppc64' ./configure -with-oci8=instantclient,/opt/oracle/instantclient_10_2/

Which gave me oci.so for all the architectures, including 64 bit:

ucommbieber:oci8 bbieber$ file modules/oci8.so
modules/oci8.so: Mach-O universal binary with 4 architecturesmodules/oci8.so (for architecture i386):    Mach-O bundle i386
modules/oci8.so (for architecture x86_64):    Mach-O 64-bit bundle x86_64
modules/oci8.so (for architecture ppc7400):    Mach-O bundle ppc
modules/oci8.so (for architecture ppc64):    Mach-O 64-bit bundle ppc64

  Maybe some of that info will help. Great article.

-Brett Bieber

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on February 20, 2009

Bibbs this is awesome! This is Reece from Wood Junior High days. I am putting you on the spot for coming out east and teaching to at-risk youth in the near future.

I myself am just getting into PHP, for some Drupal dev, so any pointers get at me @ interrupt21.com

 

Reece

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on March 09, 2009

 Hi Tony,

great article.

Following your steps I get the following errors when compiling PHP:

 

ibs/libphp5.bundle libs/libphp5.so

ld: library not found for -lclntsh

collect2: ld returned 1 exit status

make: *** [libs/libphp5.bundle] Error 1

  I read on another blog you had that problem as well. Did you find a solution for it ?

 

Working with the stock PHP5 and Apache
Authored by: Anonymous on March 17, 2009

I was starting to follow these instructions (many thanks to Tony for posting) but I didn't want to recompile apache and php, so I tried the simple way ... and it worked!

I have downloaded the latest php source (5.2.8 at the time of this writing) and the oracle instantclient (basic+sdk) for Mac OS X 10.5 Intel, "phpized" the oci8 extension, then built it as a php shared module for all possible architectures (ppc/intel 32/64 bits) and finally installed it.

Now I have the oci8 php extension working on my Xserve Intel running Mac OS X Server_10.5.6 with the stock apache_2.2.9 and php_5.2.6.

Below you can find detailed step-by-step instructions in form of a bash script; remember to fullfill its requirements first:

#!/bin/bash

# REQUIREMENTS
# download the oracle instant client (basic+sdk) and put the zip files in /opt/oracle
# download the latest php source and put the tarball in /SourceCache

# unzip the oracle instant client
cd /opt/oracle
unzip instantclient-basic-macosx-10.2.0.4.0.zip
unzip instantclient-sdk-macosx-10.2.0.4.0.zip
# create the following symbolic links, they are sometimes required at compile-time
cd /opt/oracle/instantclient_10_2
ln -s libclntsh.dylib.10.1 libclntsh.dylib
ln -s libocci.dylib.10.1 libocci.dylib

# unztar the php source tarball
cd /SourceCache
tar zxvf php-5.2.8.tar.gz

# build the oci8 extension for all architectures
cd /SourceCache/php-5.2.8/ext/oci8
phpize
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os  -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure  --with-oci8=shared,instantclient,/opt/oracle/instantclient_10_2
make

# stop apache and install the oci8 extension
apachectl stop
make install
apachectl start

I hope someone else will find this useful, let me know if it works for you too by posting an answer here.

 

Fabrizio La Rosa

 

Working with the stock PHP5
Authored by: Anonymous on March 18, 2009

Some more things:

At the end I had to recompile apache2 following the Tony's instructions (but not php5), otherwise the oci8 extension would only work from the command line ... sorry if someone has followed my suggestions wasting some hours trying to have oci8 fully at work.

Also remember to pass the appropriate environment variables to apache and PHP (DYLD_LIBRARY_PATH, LD_LIBRARY_PATH, ORACLE_HOME and so on). I did it by adding these lines to /System/Library/LaunchDaemons/org.apache.httpd.plist

    <key>EnvironmentVariables</key>
    <dict>
        <key>DYLD_LIBRARY_PATH</key>
        <string>/opt/oracle/instantclient_10_2</string>
        <key>LD_LIBRARY_PATH</key>
        <string>/opt/oracle/instantclient_10_2</string>
        <key>NLS_LANG</key>
        <string>ITALIAN.WE8ISO8859P1</string>
        <key>ORACLE_HOME</key>
        <string>/opt/oracle/instantclient_10_2</string>
    </dict>

then restarted apache 2 as root with

launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist

launchctl load /System/Library/LaunchDaemons/org.apache.httpd.plist

Now I have extensively tested the oci8 extension with the recompiled apache 2.2.11 and the stock php 5.2.6 and it's working fine.

 

Fabrizio La Rosa

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on May 26, 2009

 It works with the stock apache/php.

1) install Oracle Instant Client (in my case - under /usr/local/oracle/instantclient_10_2

2) After it's done - install Pear:

 

curl http://pear.php.net/go-pear > go-pear.php

sudo php -q go-pear.php

3) Copy /etc/php.ini.default to /etc/php.ini

4) Edit /etc/php.ini like so:

include_path=".:/usr/share/pear"

extension_dir="/usr/lib/php/extensions"

extension="oci8.so"

5) Instal oci8 from pecl:

pear install pecl/oci8

when prompted - enter "instantclient,/usr/local/oracle/instantclient_10_2" (no quotes, naturally :) )

6) When the compilation is over - you're done.

7) You need to also edit /System/Library/LaunchDaemons/org.apache.httpd.plist file like so:

 

<?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>EnvironmentVariables</key>

<dict>

<key>DYLD_LIBRARY_PATH</key>

<string>/usr/local/oracle/instantclient_10_2</string>

<key>LD_LIBRARY_PATH</key>

<string>/usr/local/oracle/instantclient_10_2</string>

<key>ORACLE_HOME</key>

<string>/usr/local/oracle//instantclient_10_2</string>

<key>TNS_ADMIN</key>

<string>/etc/oracle</string>

</dict>

<key>Label</key>

<string>org.apache.httpd</string>

<key>OnDemand</key>

<false/>

<key>ProgramArguments</key>

<array>

<string>arch</string>

<string>-i386</string>

<string>/usr/sbin/httpd</string>

<string>-D</string>

<string>FOREGROUND</string>

</array>

<key>SHAuthorizationRight</key>

<string>system.preferences</string>

</dict>

</plist>

8) That's it. Apache will run in 32-bit mode, of course, but it's really not the kind of application that needs to run in 64 bit. Now you can simply enable Web Sharing and open a "<?php phpinfo(); ?> script to verify that oci8 is there.   If you have any questions - ask away dniq at dniq-online dotcom.   P.S. I've built universal libraries for Oracle Instant Client and am going to build a universal version of oci8.so.

 

 

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on May 26, 2009

 OK, I've built the universal version of oci8.so. To do that you need to:

1) Download pecl/oci8:

pear download pecl/oci8

2) Un-tar the archive you've downloaded

3) Execute the following commands:

phpize

CC="gcc-4.3" CFLAGS="-m64 -mtune=core2" ./configure --with-oci8=instantclient,/usr/local/oracle/instantclient_10_2 && make

mv modules/oci8.so modules/oci8-64.so

./configure --with-oci8=instantclient,/usr/local/oracle/instantclient_10_2 && make

The first command will create a 64-bit version of oci8.so, the second - 32-bit one.

Now is time to build a universal library:

lipo -create -arch i386 modules/oci8.so -arch x86_64 modules/oci8-64.so -output oci8.so

You can check that you have the universal version:

file oci8.so

Now all you have to do is to copy the file to your /usr/php/extensions subdirectory.

 

To build a universal version of OIC you need to download both versions (32 bit and 64 bit) and use "lipo" to combine the two versions of each library into a universal library, then put it into /usr/local/oracle/instantclient_10_2.

 

That's all.

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on June 14, 2009

hi, my name is aftri. I was trying to install oracle on my mac, and i ran into this blog. I already have Oracle 10gR2 on my mac, and now i need to connect this with php. Since i followed your writing on OTN, I planned to instal apache and php with oci from the source. The problem is, i'm not using instantclient anymore, because I have the database installed. so when i tried to install php, it couldn't find the sdk header folder,when it's checking the oracle instant client directory. I set the instant client folder to my oracle folder that contain .dylib files. yes, that folder doesn't have sdk folder in it. so, what should i do to solve this problem? thanks.

PHP 5.2, Mac OS X Leopard and Oracle
Authored by: Anonymous on July 03, 2009

I've been having the same problem for 3 days i keep getting this error while compiling PHP :

 

ibs/libphp5.bundle libs/libphp5.so

ld: library not found for -lclntsh

collect2: ld returned 1 exit status

make: *** [libs/libphp5.bundle] Error 1

 

I've been looking like a madman with no lukc, anyone have an idae on how to solve this?

About Tony

Photo of Tony

Tony runs Apteno, L.C. a software shop specializing in open source solutions based on the Aptitude Application Framework. He's also nuts about the outdoors! Learn more ...

Topics

Noteable Blogs