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.

Pre-installation:
1. Download from the Oracle website the Oracle Client for Mac OS X (Intel x86) Version 10.2.0.4 and the SqlPlus:
- the Oracle Client ‘Instant Package – Basic’ [instantclient-basic-macosx-10.2.0.4.0.zip]
- the Oracle Client ‘Instant Package – SDK’ [instantclient-sdk-macosx-10.2.0.4.0.zip]
- the Oracle Client ‘Instant Package – SqlPlus‘ [instantclient-sqlplus-macosx-10.2.0.4.0.zip]
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]

Installation:
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
cp /Users/YOUR_MAC_USERNAME/Desktop/FOLDER_YOU_CREATED/* .
(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:
# sqlplus DB_USER/DB_PASS@//DB_SERVER:DB_PORT/DB_SID
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




Other Posts
Comments

This entry was posted on Wednesday, July 30th, 2008 at 10:42 pm and is filed under Oracle on Unix Server. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
29 Comments so far

  1. Tony Bibbs on August 19, 2008 3:29 pm

    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?

    –Tony

  2. Danilo Vizzarro on August 20, 2008 8:41 pm

    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. Scott on August 27, 2008 5:20 pm

    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. artulo on October 9, 2008 10:40 pm

    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. Danilo Vizzarro on October 16, 2008 5:24 pm

    This sounds like a php bug.

    I would say…
    # cd
    # nano .profile

    add at the end

    DYLD_LIBRARY_PATH=”/opt/oracle/instantclient_10_2″
    export DYLD_LIBRARY_PATH

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

  6. Alison Holloway on November 18, 2008 2:42 pm

    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.

    Alison

  7. Danilo Vizzarro on November 27, 2008 8:51 pm

    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

    Bye

  8. Dequin on December 30, 2008 7:47 pm

    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)

    Solution:

    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


    /usr/local/bin/phpize

    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. Mike Puchol on March 27, 2009 2:35 pm

    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 on June 18, 2009 6:43 pm

    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.

    Thanks!

  11. Josh on June 30, 2009 6:13 pm

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

  12. Mike on August 6, 2009 4:54 pm

    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. Installing Mac OS X (Intel) Oracle Client on Leopard (including PHP OCI configuration) « A bit about everything…. on August 10, 2009 6:50 pm
  14. orlando on August 17, 2009 12:17 am

    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:
    extension=/usr/lib/php/extensions/oci8.so

    now i go to try if is working….

  15. orlando on August 17, 2009 6:35 am

    not works!
    somebody know why ?

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

  16. Danilo Vizzarro on August 19, 2009 12:41 pm

    Hi Orlando,
    here how I solved the problem using a Linux machine
    http://www.danilovizzarro.it/2009/02/troubleshooting-ld_library_path-warning-ocilogon-httpfunctionocilogon-ocienvnlscreate-failed/

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

  17. Nicosa on September 6, 2009 5:59 pm

    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

  18. Simao on December 30, 2009 7:01 am

    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!

  19. Danilo Vizzarro on December 31, 2009 1:24 am

    Hi Simao,
    please execute this command:

    # echo $DYLD_LIBRARY_PATH; echo $ORACLE_HOME

    What is the output?
    Danilo

  20. Celso on January 2, 2010 9:34 am

    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:

    phpize

    by this one:

    /usr/bin/phpize

    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

  21. Antonio Musarra on August 30, 2010 2:42 pm

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

    http://musarra.wordpress.com/2009/10/29/mac-os-x-snow-leopard-php-5-3-oci8/

    Thanks,
    Antonio Musarra.

  22. Vlad on December 25, 2010 2:01 am

    there is much easier and better way:
    http://musarra.files.wordpress.com/2010/01/macosx_snow_leopard_php5-3_oci8_1-0_en.pdf

    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.

  23. Neto Terreri on January 10, 2011 3:54 am

    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.

  24. Danilo Vizzarro on January 11, 2011 12:04 am

    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
    http://juliusdavies.ca/how_to_uninstall_php_from_mac.html
    Maybe you can try and let us know if it works!
    Bye

  25. Justin Mandzik on January 16, 2011 8:15 pm

    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!

  26. Carlos on January 26, 2011 2:02 pm

    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.

  27. Joachim on February 23, 2011 8:06 am

    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

  28. Edouard Kestemont on April 1, 2013 12:45 pm

    On Mountain Lion (10.8.3), using 64 bits version of Oracle client
    instantclient-basic-macos.x64-11.2.0.3.0.zip
    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

    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 ?

    Thanks

  29. Edouard Kestemont on April 2, 2013 12:47 pm

    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 !

Name (required)

Email (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share your wisdom