Compiling php with oracle support
Hi I'm looking for some help with compiling php with oracle support on RH7.1/RH9.
I've looked at php's site and it says I need to set up some environment variables like ORACLE_HOME & LD_PRELOAD.
I know what ORACLE_HOME is but I haven't got a clue about the rest of them. Any ideas? Thanks
fintan.
Here is my own answer
Configuring apache & php with OCI8 support
For oracle support in php all you need is the oci libraries installed from the client.
Set these variables before you install the client. With this basic install of the oracle client you need to create a tnsnames.ora file and sqlnet.ora file under /path/to/your/installdir/network/admin.
export ORACLE_HOME=/path/to/your/installdir
export ORACLE_BASE=/base/dir
export ORACLE_OWNER=user
export ORACLE_SID=database
export ORACLE_TERM=xterm
export TNS_ADMIN=/path/to/your/installdir/network/admin
# Set the kernel to use the old Linuxthreads
export LD_ASSUME_KERNEL=2.4.1
export THREADS_FLAG=native
# export LD_PRELOAD=$ORACLE_HOME/lib/libclntsh.so
export NLS_LANG=AMERICAN
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
# Edit Paths
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
# CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
# CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
# export CLASSPATH # You don't need to set the CLASSPATH variable.
export PATH=$PATH #:$ORACLE_HOME/bin
Go through the normal procedure of the oracle client install but select custom install. From there select oci libraries then finish the install. From there compile apache then php with the following.
Configuring, compiling apache & php
Apache
./configure --prefix=/path/to/your/installdir --enable-so --enable-anything-else-you-want
make ; make install
PHP
./configure --with-oci8=/path/to/your/installdir –with-apxs2=/path/to/your/installdir/bin/apxs –enable-sigchild --enable-anything-else-you-want
make ; make install
When configuring php sometimes $ORACLE_HOME will work but it's better to enter the full path instead of $ORACLE_HOME.
Finishing up
After some testing I found you only need ORACLE_HOME set in apaches envvars.
export ORACLE_HOME=/path/to/your/installdir
Edit the httpd.conf file as you normally would.
Sometimes it's necessary to add the webserver user to the db group but I found you can get by without this. What you do need is a tnsnames.ora file and a sqlnet.ora file setup to point to your db server. If you have either file missing you will get this error:
Warning: ocilogon(): _oci_open_server: Error while trying to retrieve text for error ORA-12154
After much head banging I figured this out. If you google this error you get a lot of people saying its to do with your environment. In my case it was sqlnet.ora file not being created. If you still receive this error try setting the other oracle env in apache. You don't need to use putenv in php or SetEnv in apache, also you don't need to put the contents of tnsnames.ora file in a php variable.
On the two, three webservers that I've done this install these settings have worked fine. I've tested this install with rh9, httpd-2.0.48, httpd-2.0.50, php-4.3.4, php-4.3.8. When I get time I'll try it on Suse.
Conclusion
Getting oracle to work with php can be a pain in the ass but once you do it works like a charm. Thanks
fintan.
Note: If you want to use php with oracle on the comand line make sure all the environment variavles for oracle are set.
Last edited by fintan; 09-08-2004 at 10:14 AM.
|