This article originally appeared in the Oracle e-newsletter. Click

here to subscribe automatically.

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 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

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):


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


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):

<head><title>PHP Test</title></head>
<?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).

<head><title>PHP Test with
    $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 =
        echo $ename.”\n”;

Scott Stephens worked for Oracle for more than 13 years in technical support, e-commerce, marketing, and

software development. For more of his Oracle tips visit our Oracle Dev Tips