PHP Installation on Oracle Application Server 10g (9.0.4)

This article lists the steps necessary to install and configure PHP with OCI support on AS10g running on Linux. The steps are a summary of the information in the Using PHP with OracleAS 10g document provided by Oracle.
  1. execute ~oracle/infra_env.sh to set the environment. It looks (at my machine) like
    export ORACLE_BASE=/u01/app/oracle
    echo $ORACLE_BASE
    export ORACLE_HOME=$ORACLE_BASE/OraInfra_904
    echo $ORACLE_HOME
    export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/dcm/bin:$ORACLE_HOME/opmn/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
    export ORACLE_SID=asdb
    export TNS_ADMIN=$ORACLE_HOME/network/admin
    echo for installation: export LS_ASSUME_KERNEL=2.4.19
    #export LD_ASSUME_KERNEL=2.4.19
    export ORACLE_TERM=xterm
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib
    opmnctl status
  2. Download the current version of PHP from www.php.net and place it in an appropriate directory, like $ORACLE_BASE, then expand it using the following commands as the oracle software owner:
    cd $ORACLE_BASE
    gunzip php-4.3.9.tar.gz
    tar -xvf php-4.3.9.tar
  3. Download the ociheaders.tar file and place it in the "$ORACLE_HOME/rdbms/demo" directory, then expand it using the following command as the oracle software owner:
    cd $ORACLE_HOME/rdbms/demo
    tar -xvf ociheaders.tar
  4. Make sure the following environment variables are set by placing them in the oracle users profile:
    ORACLE_HOME=/u01/app/oracle/OraInfra_904; export ORACLE_HOME
    LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
    PERL5LIB=$ORACLE_HOME/perl/lib/5.6.1:$ORACLE_HOME/perl/lib/site_perl/5.6.1; export PERL5LIB
    Adjust the ORACLE_HOME value as necessary.

  5. Edit the "$ORACLE_HOME/Apache/Apache/bin/apxs" file, giving a full path for the $CFG_INCLUDEDIR variable as below:
    # Before
    my $CFG_INCLUDEDIR    = q(/include);        # substituted via APACI install
    
    # After
    my $CFG_INCLUDEDIR    = q(/u01/app/oracle/OraInfra_904/Apache/Apache/include);        # substituted via APACI install
  6. Configure and install PHP using the following commands as the oracle software owner:
    cd $ORACLE_BASE/php-4.3.9
    ./configure --with-apxs=$ORACLE_HOME/Apache/Apache/bin/apxs --prefix=$ORACLE_HOME \
     --with-config-file-path=$ORACLE_HOME/Apache/Apache/conf --with-oci8=$ORACLE_HOME --disable-rpath
    
    # Only do the following line if the previous command was successful.
    make install-sapi
    
    

    or make a file $ORACLE_BASE/php-4.3.9/php_config with this content
    echo First remove the config.cache to make a clean configuration file
    rm -f ./config.cache
    echo Configure with the following options
    ./configure --with-apxs=$ORACLE_HOME/Apache/Apache/bin/apxs --prefix=$ORACLE_HOME \
    --with-config-file-path=$ORACLE_HOME/Apache/Apache/conf --with-oci8=$ORACLE_HOME --disable-rpath
  7. Copy the php.ini file to the appropriate directory using the following command:
    cp $ORACLE_BASE/php-4.3.9/php.ini-dist $ORACLE_HOME/Apache/Apache/conf/php.ini
  8. Uncomment the following two lines from the "$ORACLE_HOME/Apache/Apache/conf/httpd.conf" file:
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps
  9. Add the appropriate entries into the "$ORACLE_HOME/network/admin/tnsnames.ora" file for the database connections you wish to make.

  10. Restart the HTTP server using one of the following commands as the oracle software owner:
    dcmctl restart -ct ohs
    
    opmnctl restartproc ias-component=HTTP_Server
    Alternatively, the following commands allow you to stop then start the HTTP server:
    dcmctl stop -ct ohs
    dcmctl start -ct ohs
    
    opmnctl stopproc ias-component=HTTP_Server
    opmnctl startproc ias-component=HTTP_Server
    
  11. Test PHP by creating a file called "$ORACLE_HOME/Apache/Apache/htdocs/test.php" with the following contents:
    <?php
      phpinfo();
    ?>
    Loading this page in a browser using a URL like "http://server:port/test.php" should produce the PHP info page and list the OCI8 component as enabled.

  12. Test the OCI extensions by creating a file called "$ORACLE_HOME/Apache/Apache/htdocs/testOCI.php" with the following contents, adjusting the connection details as required:
    <?php
      $conn = OCILogon("scott", "tiger", "DEV");
      $sql  = OCIParse($conn, "select sysdate as current_date from dual");
      OCIExecute($sql, OCI_DEFAULT);
      if (OCIFetch($sql)) {
        echo "Current Date: ".OCIResult($sql, "CURRENT_DATE");
      }
      OCILogoff($conn);
    ?>
    Loading this page in a browser using a URL like "http://server:port/testOCI.php" should produce the current datetime from the Oracle server.
For more information see:
Back to 2Question