Go4Expert (http://www.go4expert.com/)
-   Oracle (http://www.go4expert.com/articles/oracle/)
-   -   Enable PHP Support on Oracle HTTP Server (http://www.go4expert.com/articles/enable-php-support-oracle-http-server-t3610/)

pradeep 26Mar2007 16:57

Enable PHP Support on Oracle HTTP Server
When you install an Oracle database, you automatically install an Apache 1.3 HTTP server on which the database relies for many of its products and features. It seems to be a waste of resources to install a second Web server for database-driven Web site development on a single machine. It would be more efficient to simply add modules to the Oracle Apache server to support additional products.

This column describes the necessary steps for installing PHP support on the Oracle 9i default Apache Web server. We'll use Windows paths and names, but UNIX and other operating systems should be similar. (Note that Oracle has announced that Oracle 10g will include PHP support.)

The first step is to obtain the PHP module for your desired Web site from php.net. Download this module, unzip it into a directory, and build binaries (if needed) according to the installation scripts. From this point forward, I'll use c:\php as the installation root for the PHP directory containing the executables, and I'll use c:\oracle\ora92 as my Oracle Home.

Second, copy the file php4ts.dll (the scripting engine) into the sapi subdirectory. This is needed by php4apache.dll, and it's easier to locate if it's in the same directory.

Third, create a php.conf file to contain your PHP-specific settings for Oracle's Apache server:


# Apache configuration to enable PHP
 LoadModule php4_module c:/php/sapi/php4apache.dll
 AddModule mod_php4.c
 AddType application/x-httpd-php .php
 AddType application/x-httpd-php-source .phps

Save this file in the $ORACLE_HOME/Apache/Apache/conf directory. Reference it from the httpd.conf file with this line (at the very end--after oracle.conf's include):


include "C:/oracle/ora92/Apache/Apache/conf/php.conf"
Finally, copy the file php.ini-recommendation to the C:/oracle/ora92/Apache/Apache directory as php.ini. You need to enable the oracle extension to be able to access the database. First, make sure the extension_dir has the full path instead of the default "./" directory:


extension_dir = "c:/php/extensions/"
Then, uncomment the line referencing the Oracle module:


Restart the Web server normally and check for errors. You should be able to write a very simple PHP script (save as test.php in $ORACLE_HOME/Apache/Apache/htdocs):

HTML Code:

  <Title>PHP Test</Title>
    <?php echo "Hello World"; ?>

You should also be able to run a full PHP script, which accesses an Oracle database via PHP extension calls (save it as oratest.php in $ORACLE_HOME/Apache/Apache/htdocs).

Code: PHP

 PHP Test with Oracle<head>
     $conn = ora_logon("scott","tiger");
     $cursor = ora_open($conn);
     ora_parse($cursor,"select initcap(ename) from emp order by 1");
     while (ora_fetch($cursor))
         $ename = trim(ora_getcolumn($cursor,"ENAME"));
         echo $ename."\n";

lead.smart34 26Feb2008 18:09

Re: Enable PHP Support on Oracle HTTP Server
good info

trinitybrown 25Oct2008 12:36

Re: Enable PHP Support on Oracle HTTP Server
Good article but why one should go for oracle when MySQL is there

Jenniferlinn 27Dec2008 16:51

Re: Enable PHP Support on Oracle HTTP Server
Hello pardeep

Thanks for the post as till now i never think to use any other database with PHP but now i will try to use oracle with PHP

All times are GMT +5.5. The time now is 09:14.