Using PHP with Oracle HTTP Server 11g

Oracle HTTP Server is the web server component in Oracle Fusion Middleware. Based on the Apache infrastructure, Oracle HTTP Server allows developers to program their site in a variety of languages and technologies.

PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a general-purpose scripting language often used for generating web sites. The object model of PHP 5 facilitates project development using standard object-oriented methodologies.

With the exponential growth in the use of PHP, mod_php has become the most requested module for Apache. Although PHP interpreter, language and server side module (mod_php) do not ship with the Oracle HTTP Server 11g release, Oracle will assists customers in configuration and inclusion of mod_php into Oracle HTTP Server. Note that Oracle does not support the PHP interpreter and language but it supports Oracle HTTP Server 11g release with mod_php included.

This document provides detailed instructions on how to install and configure PHP to work with Oracle HTTP Server 11g. The following steps have been tested successfully with PHP v5.2.9 and v5.3 and Oracle HTTP Server 11g on Linux platform.


1. Pre requisites
    1.1  System Requirements
    1.2  Software Requirements

2. Configuring mod_php on Linux 
    2.1  Pre install steps 
    2.2  Setting up the environment 
    2.3. Configure & install 
    2.4  Post Install step

3. Testing your configuration  

1.  Pre requisites

1.1  System Requirements

Before performing any installation you should read the system requirements and certification documentation to ensure that your environment meets the minimum installation requirements for the products you are installing.

1.2  Software Requirements

2.  Configuring mod_php on Linux

Login as the OS user that installed and configured Oracle HTTP Server and perform following tasks. If you are using PHP 5.2 and want to configuring with Oracle Database (OCI8) support, Oracle recommends you upgrade OCI8 1.3 using the OCI8 extension available at Do this by installing PHP without OCI8 using the instructions below and then use the 'pecl install oci8' command.

2.1  Pre install steps  

  1. Oracle HTTP Server 11g should be installed and configured on the same host where you will be installing and configuring PHP.

    Oracle Home directory listing. Here ~/oraHome1 is assumed to be the location where Oracle Home, that contains Oracle HTTP Server binaries, is installed.

       +-- ohs  
       |   +-- bin  
       |   +-- lib
       +-- lib  
       +-- perl 
       |-- ...  

    Oracle Instance directory listing. Here ~/oraInstance1 is assumed to be the location where Oracle Instance, that contains Oracle HTTP Server component named "ohs1", is created.

       +-- config   
       |   +-- OHS   
       |   |   +-- ohs1   
       |   |-- ...  
       |   +-- OPMN   
       |   |   +-- opmn   
       |-- ...  

    To learn more about Oracle Home and Oracle Instance concepts, refer
    Oracle Fusion Middleware Concepts Guide 11g Release 1 . Also to understand more about Oracle HTTP Server directory structure, refer Oracle Fusion Middleware Administrator's Guide for Oracle HTTP Server 11g Release 1 .

    To make sure Oracle HTTP Server is installed and configured properly, see if Oracle HTTP Server welcome page can be launched successfully by going to the URL  http://<ohs_host.domain>:<ohs_port >.

  2. Download php-5.x.x.tar.gz from . Place it at any location (for the purpose of documentation we assume its ~/ ).

  3. Unzip the file using the command:

    $ gunzip php-5.x.x.tar.gz

    This will give you php-5.x.x.tar file.

  4. Un-tar the file using this command:

    $ tar -xvf php-5.x.x.tar

    This will create a directory php-5.x.x. The contents of this directory will be like:
       |-- build 
       |-- configure 
       |-- php.ini-dist 
       |-- libtool 
       +-- sapi 
       |-- ...  

    Skip steps e) and f) below if you do not want Oracle Database (OCI8) support and go directly to Section 2.2, "Setting up the environment" .
  5. Create a new directory "demo" under $ORACLE_HOME/rdbms.

  6. Download the OCI headers tar file to $ORACLE_HOME/rdbms/demo directory and un-tar it using following command:

    $ tar -xvf ociheaders.tar

    The contents of this directory will be like:

       +-- ohs    
       +-- rdbms    
       |   |-- demo    
       |       |-- oci.h    
       |       |-- ociap.h    
       |       |-- oratypes.h    
       |       |-- ...    
       |       |-- ...    
       |-- ...  

2.2  Setting up the environment


Bash shell:  
   export ORACLE_HOME=~/oraHome1
   export ORACLE_INSTANCE=~/oraInstance1

C shell:  
   setenv ORACLE_HOME ~/oraHome1   
   setenv ORACLE_INSTANCE ~/oraInstance1  

2.3  Configure & install

With the pre install steps done we are now ready to configure PHP.

  1. Navigate to ~/php-5.x.x directory. Run the configure command with either of the following options: 

    Configure without Oracle Database (OCI8) support:

    $./configure --with-apxs2=$ORACLE_HOME/ohs/bin/apxs --prefix=$ORACLE_HOME --with-config-file-path=$CONFIG_FILE_PATH

    Configure with Oracle Database (OCI8) support:

    $./configure --with-apxs2=$ORACLE_HOME/ohs/bin/apxs --prefix=$ORACLE_HOME --with-config-file-path=$CONFIG_FILE_PATH --with-oci8=$ORACLE_HOME --disable-rpath

    Notes: Above config command might appear to be in multiple lines but it is all one line

    If you want PHP XML support:

    • Download libxml2 from and install it in $ORACLE_HOME/libxml2 directory.
    • Make sure that the libxml2 version you download is consistent with the PHP version being used.
    • Add "--with-libxml-dir= $ORACLE_HOME/libxml2" to your 'configure' command options.

    You may also add any other config options desired.

  2. If 'configure' succeeded without any errors issue the 'make' command at the command prompt.

    $ make

    $ make install

Once the make command is executed properly:

  • is generated in the ~/php-5.x.x/libs/ directory and copied to $ORACLE_HOME/ohs/modules directory.
  • $CONFIG_FILE_PATH/httpd.conf file is updated to load the php5_module.

2.4  Post install steps

Now that the required files are generated and copied in the appropriate locations, we have to tell Oracle HTTP Server to service the requests for .php/.phtml/.phps type extensions and restart Oracle HTTP Server. 

  1. Copy the default PHP settings file to $CONFIG_FILE_PATH directory:

    For PHP 5.2:

    $ cp ~/php-5.x.x/php.ini-dist $CONFIG_FILE_PATH/php.ini

    For PHP 5.3:

    $ cp ~/php-5.x.x/php.ini-production $CONFIG_FILE_PATH/php.ini

  2. Navigate to the $CONFIG_FILE_PATH directory and edit the httpd.conf file to add the following:

    # And for PHP 5.x use:
    AddType application/x-httpd-php .php .phtml

    If you wish to view PHP source code, add the following to make sure any filenames ending with .phps will be displayed nicely and not executed:

    AddType application/x-httpd-php-source .phps

  3. For mod_php with Oracle Database (OCI8) support, add the connect string for the Oracle database you want to access in your tnsnames.ora file. The default location of tnsnames.ora file is $ORACLE_HOME/network/admin directory.
  4. Finally Oracle HTTP Server should be restarted for the changes to come into effect.

    $ cd $ORACLE_INSTANCE/bin

    $ ./opmnctl stopproc ias-component=ohs1

    $ ./opmnctl startproc ias-component=ohs1

  5. Go to Section 3, "Testing your configuration" to test your configuration.

3.  Testing your configuration   

  1. Unzip the contents to $CONFIG_FILE_PATH/htdocs directory. The contents of this directory will be like:

       +-- config   
       |   +-- OHS   
       |   |   +-- ohs1
       |   |   |   +-- htdocs
       |   |   |   |   |-- demo
       |   |   |   |       |-- phpinfo.php  
       |   |   |   |       |-- dbtest01.php 
       |   |   |   |       |-- dbtest02.php 
       |   |   |   |       |-- dbtest03.php  
       |-- ...  

  2. Before accessing the DB test script files (dbtest*.php) edit them and set the values of $username, $password and $dbname variables to your database credentials.

  3. Run the test PHP page by going to following URL:

    Without Oracle Database support:

    With Oracle Database support: