How to install and configure PHP so that it will connect to Oracle on a remote server. I spent my entire day combing the web, and emailing very freindly people to figure this all out. In an effort to help others who run into the same problems I did (and from the number of posts out there, there seem to be quite a few), I have compiled the following (which is taken from the records I made for my company). These instructions apply to RH Linux 7.2 Enjoy...
First, you have to install the Oracle client at a minimum. This is done by downloading the entire linux81707.tar
package from Oracle.com (or you can get it from a CD).
Download the jre1.1.8_v3 from www.blackdown.org, there are two packages. One is smaller than the other and it won't work!
The rest of the Oracle installation steps depend on the version of Linux you are running. If you are working with RH 7.2, you will need to cull information from two sites (both have incomplete info!). Keep in mind, though you have downloaded the entire Oracle package, you only need to install the Net8 Client and SQLPlus (I strongly recommend doing a custom install of the Oracle Client):
http://staff.in2.hr/denis/oracle/817install_rh72_en.html
AND
http://jordan.fortwayne.com/oracle/817.html
Once Oracle is installed, make sure you have confirmed that you can connect to your Oracle server from SQLPlus before proceeding. If you can't, don't proceed until you have succesfully connected.
Now that Oracle has been successfully installed and tested, compile PHP with Oracle support:
--with-oracle=/path/to/ora and --with-oci8=/path/to/ora --with-apxs=/path/apxs
You can choose which compilation options you want (you can do both oci8 and oracle, but you don't need both). Next make sure that Apache has been configured with links to pthread. You can confirm this by doing the following:
ldd /path/to/httpd
This should show you the following if Apache was correctly configured:
ldd /www/apache/bin/httpd
-->libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000)
libm.so.6 => /lib/libm.so.6 (0x4002f000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000)
libdl.so.2 => /lib/libdl.so.2 (0x4007a000)
libc.so.6 => /lib/libc.so.6 (0x4007e000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
If the libpthread is not listed you have to reinstall Apache, as below:
cd /apache/src/location
make clean
LIBS=-lpthread ./config.status
make
make install
After successful confirmation/re-installing apache, add the following to your apachectl script:
set up Oracle environment
if [ "x$ORACLE_HOME" = "x" ] ; then
export ORACLE_BASE=/u01/app/oracle/
export ORACLE_HOME=$ORACLE_BASE/product/8.1.7
export TWO_TASK=ORADEV
export ORACLE_SID=ORADEV
export PATH=$ORACLE_HOME/bin:$PATH
export LD_PRELOAD=$ORACLE_HOME/lib/libclntsh.so.8.0
fi
Now, you need to insure that you have a tnsnames.ora file that is correctly configured. This file will be located in
/oracle/home/network/admin. If you configured your Net8 during the Oracle install you will have a tnsnames.ora file
located here. It will probably be incorrect. This means, you will need to talk to the Oracle dba (unless you're it)
and ask them how the file should look. Below is an example of how a tnsnames.ora file might look:
TNSNAMES.ORA Network Configuration File: D:\oracle\ora81\network\admin\tnsname
s.ora
Generated by Oracle configuration tools.
SID.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = service.com)
(PRESENTATION = http://admin)
)
)
A big note - Working with PEAR, you don't use the standard dsn configuration seen in most examples on the web. You feed the DB::Connect method one of the following strings:
DB::Connect("oci8://user:pass@SID");
Alternatively, you can use
DB::Connect("oci8://user:pass@");
If you're using phpbt, like I am - this means you will have to alter the install.php and include.php files - using the standard install method didn't work for me.
As of the writing of this document, I have successfully connected to Oracle from PHP using the following method, and that listed above:
<?
// open a connection
if (!$db = ora_logon("user@SID","password")) {
$error = ora_error();
printf("There was an error connecting. Error was: %s", $error);
die();
}
$curs = ora_open($db);
?>
Now, see how simple that was?
All the best,