Created on: 2005-12-11
Last Revised: 2007-02-27
Apache: 2.2.4
PHP: 4.4.5
Oracle: 10g R2
OS: CentOS 4.4

Note: This is also a year old. But helps understand the basic principle of combining Apache, PHP and Oracle.

NOTE: NOTE: NOTE: REMOVE APACHE RPM, or else you will be pulling your hair afterwards. YOU HAVE BEEN WARNED!

Oracle 10gR2 client was installed in /oracle as type: “Run Time”

After installation of Oracle software is completed, it is better to run ldconfig once.

~]# ldconfig

Apache was installed using :

~]# mkdir /www    
  
~]# cd /tmp/httpd-2.2.4    
  
httpd-2.2.4]# ./configure --prefix=/www --exec-prefix=/www --bindir=/www/bin --sysconfdir=/www/conf --libdir=/www/lib  --enable-module=so  
  
httpd-2.2.4]# make && make install && echo "Apache Installation Success" || echo "Apache FAILED"  
  
~]# cd /tmp/php-4.4.5  

php-4.4.5]# export ORACLE_HOME=/oracle/product/10.2.0/db_1  
  
php-4.4.5]# export ORACLE_SID=orcl  
  
The following will work for "Administrator" and "Runtime" versions of Oracle Client software installation only :  
  
php-4.4.5]# ./configure --prefix=/www/php --with-apxs2=/www/bin/apxs --with-config-file-path=/www/php --with-oci8=$ORACLE_HOME --enable-shared=$ORACLE_HOME/lib --disable-xml --without-pear --enable-sigchild  
    
php-4.4.5]# make && make install && echo "PHP Installation Success" || echo "PHP FAILED"  
  
php-4.4.5]# libtool --finish /tmp/php-4.4.5/libs  
  
  
This step is not required:  
  
~]# chmod o+rx  /oracle -R  
  
  
~]# vi /www/conf/httpd.conf  
  
(Make the following changes:-)  
  
ServerAdmin webmaster@yourdomain.com  
ServerName dbserver.yourdomain.com  
  
AddType application/x-httpd-php .php .phtml  
  
DirectoryIndex index.php index.html index.html.var  
  
LoadModule php4_module        modules/libphp4.so  # (Normally it already exists, you don't have to write yourself)  
  
  
~]# vi /www/bin/envvars  
  
# This file is generated from envvars-std.in  
#  
export ORACLE_HOME="/oracle/product/10.2.0/db_1"  
export ORACLE_BASE="/oracle/"  
export ORACLE_SID="orcl"  
LD_LIBRARY_PATH="/www/lib:$LD_LIBRARY_PATH:$ORACLE_HOME/lib"  
export LD_LIBRARY_PATH  
  
  
To check PHP:  
  
~]# vi /www/htdocs/index.php  
  
  
~]# vi /www/htdocs/test.php  
  
if ($conn=OCILogon("scott", "tiger", "orcl")) {  
echo "
Active
======
";  
}else {  
$err = OCIError();  
echo "
Failed
======
";  
}  
?>  
  
( Test your entire setup by this script. Should show you "Active" on your web page. )  
  
  
Now this is the part which made me too mad for a week. It gave nme all kind of weird messages, like: "unable to retrieve text", etc etc.  
  
The application developers were over-riding the variable settings of my apache server  
  
~]# vi /www/htdocs/dsn/conn.php  
  
  
##########################################################################################  
# As you can see these settings from application were causing all stupid errors  
# So I commented them and things become all ok.  
# There is no need to setup these variables here as they are setup in /www/bin/envvars file  
#########################################################################################  
  
#putenv("ORACLE_BASE=/u01/app/oracle/product/10.1.0/Db_1");  
#putenv("ORACLE_HOME=/u01/app/oracle/product/10.1.0/Db_1");  
#putenv("ORACLE_SID=FPSC");  
#putenv("NLS_LANGUAGE=FRENCH_FRANCE.WE8ISO8859P1");  
#putenv("TNS_ADMIN=/u01/app/oracle/product/10.1.0/Db_1/network/admin");  
#putenv("TNS_ADMIN=/u01/app/oracle/product/10.1.0/Db_1");  
#putenv("ORA_NLS33=/u01/app/oracle/product/10.1.0/Db_1/ocommon/nls/admin/data");  
#putenv("LD_LIBRARY_PATH=/u01/app/oracle/product/10.1.0/Db_1/lib:/u01/app/oracle/product/10.1.0/Db_1/network");  
  
###############################################################################################################  
  
if(!$conn) {  
  
$conn=OCILogon("scott", "tiger", "orcl");  
if($error = OCIError()) {  
die("ERROR!! Couldn't connect to server!");  
}  
}  
?>  
  
  
Now setup Apache to start at boot time.  
~]# vi /etc/rc.local  
/www/bin/apachectl -k start && echo "Apache startup OK" || echo "Apache startup FAILED" ; sleep 3

Or you can setup an init.d script for this.

DONE.