On Feb 3, 2008, at 16:14, John Korchok wrote:
For anyone else who may be struggling with getting Oracle to play with MacPorts PHP, here are my notes after installation on three systems and about 100 hours of tinkering. Start with a PowerPC, as the Oracle Instant Client for Mac does not yet work with Intel machines.
1. Install php5 with oracle support: sudo port install php5 +apache2 +oracle
2. So that the Apache user can find the relevant files, add environment variables to opt/local/apache2/bin/envvars: export LD_LIBRARY_PATH="/opt/local/lib/oracle" export TNS_ADMIN="/Applications/Oracle" (or whatever folder is a convenient spot to store sqlnet.ora and tnsnames.ora) Many web sites refer to setting DYLD_LIBRARY_PATH, you can do that instead of LD_LIBRARY_PATH and it has the same effect. Heck, use 'em both for good measure!
I'm surprised LD_LIBRARY_PATH has any effect. I thought that was for Linux and DYLD_LIBRARY_PATH was the Mac OS X equivalent. I'm also surprised you needed to set this variable at all. I thought that fixing the library name with install_name_tool like I do in the portfile would make this unnecessary. What error occurs if you do not set this variable?
Do _not_ use putenv in a PHP script or SetEnv in httpd.conf to set the variables, it won't work. Apache will also not pick up environment variables from /private/etc/profile. Note to Ryan: can MacPorts update envvars?
MacPorts can set environment variables for its own use during any of the phases (configure, build, destroot, etc.). However these do not persist after the port has been installed.
3. Restart Apache
For testing purposes, you can also add support for SQLPlus from the command line by downloading the Instant Client SQLPlus files from http://www.oracle.com/technology/software/tech/oci/instantclient/ htdocs/macs oft.html and copying them to opt/local/lib/oracle. In that case you will have to add these variables to /Users/YourUserName/.profile: export LD_LIBRARY_PATH="/opt/local/lib/oracle:$LD_LIBRARY_PATH" export TNS_ADMIN="/Applications/Oracle" export PATH="/opt/local/lib/oracle:$PATH" If you prefer all users to have SQLPlus access, add the variables to /private/etc/profile
If you have trouble with errors like "ORA-12154: TNS:could not resolve the connect identifier specified", Oracle may not be able to read your tnsnames.ora file. We had to amend the first line from "ALIG" to "ALIG.revion.com" (appending the url of the host name) to get it to work. Here are connection strings for PHP and SQLPlus, respectively: $con = OCILogon('YourUserName', 'YourPassword', "//your.host.address.com:1521/YourServiceName"); sqlplus YourUserName/YourPassword@//your.host.address.com:1521/YourServiceName
If all else fails, you can use a verbose connection string to eliminate any need for tnsnames.ora: $con = oci_connect('YourUserName', 'YourPassword', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=your.host.address.com) (PORT=1521) )(CONNECT_DATA=(SID=YourServiceName)(SERVER=DEDICATED)))');
Here's the verbose syntax for SQLPlus: sqlplus YourUserName/YourPassword@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=TCP\)\ (HOST=you r.host.address.com\)\(PORT=1521\)\)\(CONNECT_DATA=\ (SID=YourServiceName\)\(S ERVER=DEDICATED\)\)\)