Warning: count(): Parameter must be an array or an object that implements Countable in /home/idearlac/public_html/danilovizzarro.it/wp-includes/post-template.php on line 284

HOW-TO: Install PHP5, OCI8, the Oracle Client v10.2 and SqlPlus on Mac OS X Leopard 10.5.4

Posted by in Oracle on Unix Server

Get the OCI8 module working on a Mac require several settings. I wrote a script to automate the procedure that install and configure SqlPlus, the Oracle Client v10.2, Apache2, PHP5 and the OCI8 on a Mac OS X running Leopard. The script was tested on a Leopard 10.5.4 machine. I have never tested it on Tiger but I don’t recommend to test it there without having an idea of how to backup and restore all the Apache configuration files.

1. Download from the Oracle website the Oracle Client for Mac OS X (Intel x86) Version and the SqlPlus:
– the Oracle Client ‘Instant Package – Basic’ [instantclient-basic-macosx-]
– the Oracle Client ‘Instant Package – SDK’ [instantclient-sdk-macosx-]
– the Oracle Client ‘Instant Package – SqlPlus‘ [instantclient-sqlplus-macosx-]
2. Download the bash script MacOracleViaPHP.sh. Last version can be found in the script page.
3. Download the last version of the following programs respecting the file format
Apache2 [httpd-X.X.X.tar.gz]
PHP5 [php-5.X.X.tar.gz]
OCI8 [oci8-X.X.X.tgz]

1. Copy all these files in your Mac directory /var/root in the following way
– Create a folder on the desktop and move all the files in this folder
– Open the terminal
– If you don’t have a root password set you will need to set one
# sudo passwd
– Log in as root
# su –
– Copy the files inside the folder you created into the root directory /var/www
(don’t forget the dot ‘.’ at the end of the command)
– Check that the files are in the right place
# cd /var/root
# ls
2. Enter the home directory of the user root, change the permissions of the installation script and execute it.
# cd
# chmod 755 MacOracleViaPHP.sh
# ./MacOracleViaPHP.sh
3. Type: Oracle SID, Oracle Server, Oracle Server Port, Oracle Database Username, Oracle Database Password.

Installation Check:
1. To connect the Oracle DB via SqlPlus you can run the following command:
2. To check that PHP can connect Oracle, opening the page http://localhost/info.php you could see the OCI8 module enabled, and opening the page http://localhost/test.php you could connect the Oracle DB.

Your comment, error reports and improvement requests are always welcome ;D

# # # # # # #

29 thoughts

  1. Hello, hey I found this handy bash script for building Apache/Oracle Client/PHP. I’m trying to get my arms around what it is doing and I’m omitting the Apache build as I already have it the way I think I need it. That said I’ve run the following process. I tried passing the CFLAGS_CLEAN and EXTRA_LDFLAGS in manually instead of

    #> ./configure --with-xsl --enable-soap --with-zlib --with-iconv=/sw --enable-xml=/sw --enable-libxml=/sw --with-oci8=instantclient,/Users/tony/instantclient/instantclient_10_2/ --enable-cli --with-apxs2
    #> cp makefile makefile.backup
    #> cat makefile | sed 's/CFLAGS_CLEAN = /CFLAGS_CLEAN = -I/usr/include -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk #CFLAGS_CLEAN = /' > makefile1.tmp
    #> cat makefile1.tmp | sed 's/EXTRA_LDFLAGS = /EXTRA_LDFLAGS = -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk #EXTRA_LDFLAGS = /' > makefile2.tmp
    #> rm makefile
    #> mv makefile2.tmp makefile
    #> rm makefile1.tmp

    All seems well but when I do a make I get this:

    ldld: library not found for -lclntsh
    collect2: ld returned 1 exit status
    : library not found for -lclntsh
    collect2: ld returned 1 exit status
    lipo: can’t open input file: /var/tmp//ccXPBMNF.out (No such file or directory)
    make: *** [libs/libphp5.bundle] Error 1

    Any ideas on what might cause this error? Also is there a way to pass the CFLAGS_CLEAN and EXTRA_LDFLAGS values in without hacking up the makefile?


  2. Hi Tony,
    all the versions of Leopard have by default Apache installed but I have found more confortable to build it again from scratch cause it would have been easier to avoid errors.
    I don’t have a quick solution in mind. Why don’t you try to post your issue on http://lists.apple.com/mailman/listinfo ?
    Of course if you got it solved would be great if you could share your information.
    Thank you

  3. Great script.

    I ended up having to review the phpinfo() values for the configuration file path (php.ini) and extension_dir. These values remained as they were configured by Apple. In the end, I ended up moving the php.ini. Apache/libphp5.so is using /usr/local/lib/php.ini and the CLI is using /etc/php.ini.

    Thanks again.
    – Scott

  4. Still working on this. I fixed my previous error, and now info.php shows oci8 and the webserver starts properly. When I try to run a test script to connect to an oracle server I get the following:

    Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client libraries.

    I’ve checked and they’re in there when I echo $PATH.

    Any hints? I’m sure it’s something simple…

  5. This sounds like a php bug.

    I would say…
    # cd
    # nano .profile

    add at the end


    then restart apache.
    Let us know if it works then ;-)

  6. Your script works like a charm. Thanks for putting this on the web. I was just wondering if there’s anything else that needs to be done on a restart of the system? I rebooted and couldn’t get the web server started. I tried restarting as root, but no luck.


  7. Hi Alison,
    the script doesn’t affect the startup of the webserver when you boot the system. If you still have problems you can try this http://ubuntuforums.org/showthread.php?p=929849#post929849


  8. I found this script and love it!… but it didn’t workout for me, just like it didn’t for tony.

    I actually fight with it, googled it, forumed it and nothing but that bloody error: “…OCIEnvNlsCreate() failed…”

    Found that message Tony referer to and after several hours I found the solution (and the cause)


    First add -L/opt/oracle/instantclient_10_2 to the EXTRA_LDFLAGS in the php makefile or edit the script like this

    cat makefile1.tmp | sed 's/EXTRA_LDFLAGS = /EXTRA_LDFLAGS = -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -L/opt/oracle/instantclient #EXTRA_LDFLA
    GS = /' > makefile2.tmp

    Second was to eliminate every reference to ppc architecture

    And Third to use


    instead of phpize, to compile oci8.

    That’s it.

    The Cause? well IMHO the problem it’s caused because the script replace the varible EXTRA_LDFLAGS and, consecuently, the oracle’s library location.

    Oh, and one more other thing, edited httpd.conf adding these lines:

    # Turned on env_module to set Oracle stuff here.

    SetEnv ORACLE_HOME /opt/oracle/instantclient_10_2
    SetEnv LD_LIBRARY_PATH /opt/oracle/instantclient_10_2
    SetEnv DYLD_LIBRARY_PATH /opt/oracle/instantclient_10_2
    SetEnv TNS_ADMIN /opt/oracle/tns

  9. Thanks for sharing this excellent script – I ran into the “lclntsh not found” error while building PHP. It seems this issue is posted several times around forums, blogs and newsgroups, but nobody ever answers…

    Not sure if links were working, I created copies of the libraries to their .dylib equivalent, and I also changed your script – in the second cat on PHP’s Makefile, you add /opt/oracle/instantclient instead of /opt/oracle/instantclient_10_2 which is what ./configure is used with. With this change, everything worked fine.

  10. Israel Garcia

    June 18, 2009

    I just made it!

    Thanks to the script plus Dekin and Mike’s mods. Basically get rid of -arch ppc (I’m on an Intel Mac) and follow Dekin and then Mike’s comments regarding the PHP’s makefile.

    Works like a charm.


  11. How do i make a clean install? As in which files do i have to delete ? :S

  12. Thanks for sharing your script. The install went well, but I did run into the same problem with the library not being found. I was able to correct that issue using Dequin’s comments above.

    Unfortunately I am still having problem connecting to a remote Oracle server using PHP. I have no problem connecting to the same server using SQLPLUS as ROOT.

    The error I am getting is “Fatal error: Call to undefined function oci_new_connect()”

    Any ideas what might be causing this issue. It seems like php may not be configured properly but I am not sure. Any help would be greatly appreciated.

  13. after hours of try, the phpinfo() show me the OCI8 extension!

    all that i do is:
    locate oci8.so
    and copy this path to the php.ini

    in my case:

    now i go to try if is working….

  14. not works!
    somebody know why ?

    oci_new_connect() [function.oci-new-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client libraries

  15. Hi Orlando,
    here how I solved the problem using a Linux machine

    On Mac I haven’t tested the solution but should be similar.

  16. Hello,

    Thanks for this HowTo and script. I’ve had problem when “make” for the php part : The sed command did comment too much for EXTRA_LDFLAGS (add to remove the #EXTRA_LDFLAGS to let the “-L /path/to/instant/client” be used. also add to remove “-arch ppc” on both lines modified by sed to avoid some other error).

    This done on MacBook Pro (MBP 3.1, MacIntel) with Leopard 10.5.7

  17. Hi there! Great script but i’m having a problem :/
    When i try to run the sqlplus command i get this error:

    dyld: Library not loaded: /b/227/sqlplus/lib/libsqlplus.dylib
    Referenced from: /usr/bin/sqlplus
    Reason: image not found
    Trace/BPT trap

    Any help on that?

    Also, i get nothing on the phpinfo() or the test.php pages.

    Thanks a lot!

  18. Hi Simao,
    please execute this command:


    What is the output?

  19. Greetings!

    I’m having some problems with your script… I have snow leopard, and tried the script more than 10 times now, and it never worked…. I had installed MAMP, but then I realize that MAMP is unnecessary in snow leopard.

    I tried with the original and it didn’t work for me. I’ve been editing the script according to the comments i read, and it still doesn’t work. As Simao, I get nothing with phpinfo() and the test.php. I’ve been trying to spot errors within the installation, and I spotted this one the last time I tried:

    libs/libphp5.bundle && cp libs/libphp5.bundle libs/libphp5.so
    i686-apple-darwin10-gcc-4.2.1: =: No such file or directory
    make: *** [libs/libphp5.bundle] Error 1

    In the end, I get:

    Build complete.
    Don’t forget to run ‘make test’.

    Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20090626/

    Until now, I made these changes in the script:

    1) Replace this line:

    #cat makefile | sed ‘s/CFLAGS_CLEAN = /CFLAGS_CLEAN = -I/usr/include -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk #CFLAGS_CLEAN = /’ > makefile1.tmp

    by this one:

    cat makefile | sed ‘s/CFLAGS_CLEAN = /CFLAGS_CLEAN = -I/usr/include -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk #CFLAGS_CLEAN = /’ > makefile1.tmp

    2) Replace this line:

    cat makefile1.tmp | sed ‘s/EXTRA_LDFLAGS = /EXTRA_LDFLAGS = -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk #EXTRA_LDFLAGS = /’ > makefile2.tmp

    by this one:

    cat makefile1.tmp | sed ‘s/EXTRA_LDFLAGS = /EXTRA_LDFLAGS = -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -L/opt/oracle/instantclient_10_2 = /’ > makefile2.tmp

    3) Replace this line:


    by this one:


    4) I also edited httpd.conf adding these lines:

    # Turned on env_module to set Oracle stuff here.

    SetEnv ORACLE_HOME /opt/oracle/instantclient_10_2
    SetEnv LD_LIBRARY_PATH /opt/oracle/instantclient_10_2
    SetEnv DYLD_LIBRARY_PATH /opt/oracle/instantclient_10_2
    SetEnv TNS_ADMIN /opt/oracle/tns

  20. Hi Danilo,
    good post.
    I wish to notify you, I wrote a post in italian on my blog that is always the same topic.


    Antonio Musarra.

  21. there is much easier and better way:

    it uses pecl to install OCI8 module for PHP, no need for rebuilding PHP and Apache. Native Leopard’s Apache and PHP will work like a charm.

  22. Neto Terreri

    January 10, 2011

    Hi Danilo. First I would like congratulations for this post and script!! it’s amazing!! I have a little problem with Snow Server (10.6.6). He comes with php 5.3.3 by default. I run your script with php 5.2.6 normaly installing all features including oci8. But he keeping the php 5.3.3. I would like know if in your script have a way to uninstall the php 5.3.3 for install 5.2.6 or replace 5.3.3. Thank you.

  23. Hi Neto,
    I would suggest first to uninstall the current PHP version you have installed and then to execute the script I wrote.
    I didn’t try by my self to uninstall PHP but I have found this instruction
    Maybe you can try and let us know if it works!

  24. Justin Mandzik

    January 16, 2011

    Just a quick note: Double check you switched to root with `sudo su -` as opposed to `sudo bash` before you ran Danilo’s script. Many of the issues people have been having appear related to unix account environmentals and this will make sure the `root` user has the appropriate settings, not the regular mac account.

    Good luck!

  25. Hi all …

    Danilo, first of all thank you for the great post and the scripts.

    I did everything you said, and when I try to execute the sqlplus command to check connectivity with Oracle I receive the following message:

    dyld: Library not loaded: /b/227/sqlplus/lib/libsqlplus.dylib
    Referenced from: /usr/bin/sqlplus
    Reason: image not found
    Trace/BPT trap

    if I echo both $ORACLE_HOME and $DYLD_LIBRARY_PATH I get ”/opt/oracle/instantclient_10_2″

    ¿Any idea?

    Thank you very much in advance.

  26. I Did anthing but the apache errorlog said if i open the test.php:
    ming normal operations
    dyld: lazy symbol binding failed: Symbol not found: _OCIEnvNlsCreate
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so
    Expected in: flat namespace

    dyld: Symbol not found: _OCIEnvNlsCreate
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so
    Expected in: flat namespace

    any idea

  27. On Mountain Lion (10.8.3), using 64 bits version of Oracle client
    and related files, then using PECL, osi8.so is apparently correctly installed in /usr/lib/php/extensions/no-debug-non-zts-20090626

    SQLPlus works.

    php –ri oci8 gives the same error message as the one of Joachim

    $ php –ri oci8


    OCI8 Support => enabled
    Version => 1.4.9
    Revision => $Id: e2241cffb72c940cb2ca267b7a6a0ce436de7e5e $
    Active Persistent Connections => 0
    Active Connections => 0
    dyld: lazy symbol binding failed: Symbol not found: _OCIClientVersion
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so
    Expected in: flat namespace

    dyld: Symbol not found: _OCIClientVersion
    Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so
    Expected in: flat namespace

    Trace/BPT trap: 5

    I find no trace of oci8 in phpinfo()…

    Any ideas ?


  28. I still had the old libclntsh.dylib.10.1 installed in /usr/lib and the symbolic link pointed to this old library.
    Removing libclntsh.dylib.10.1 and with the correct symbolic link OCI8 is finally installed.
    Confirmed with php –ri oci8 and phpinfo() after apache restart.

    (Mountain Lion 10.8.3 ; 64 bits Oracle instantclient packages)

    Thank you very much for your tutorial !