How to Use PHP with Oracle Admin

Introduction

This page provides a procedure to configure PHP with Oracle Instant Client libraries on a FreeBSD system, enabling users to query Oracle databases from PHP scripts.

FreeBSD has an Oracle instantclient port, but to use it, you first need to manually download and move Oracle's instantclient-basic-linux* file from Oracle's domain (because of licensing restrictions). Match the downloaded Oracle instantclient file version with the FreeBSD Oracle instantclient port you're trying to install. Match the chip architecture, too... We're using 64-bit in this exercise.

Procedure

  1. Which version of PHP are you using?
    
    % php -v
    PHP 5.3.6 with Suhosin-Patch (cli) (built: Jul  8 2011 21:53:53) 
    Copyright (c) 1997-2011 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
    
    
  2. Try to install the Linux Oracle InstantClient SDK port. It will fail on your first attempt, but that's okay. You need to see the error message explaining why it fails.
    
    % cd /usr/ports/databases/linux-oracle-instantclient-sdk
    [cheshire] linux-oracle-instantclient-sdk% sudo make install clean
    Password:
    ===>  linux-oracle-instantclient-sdk-10.2.0.3.20061115 
    
    -=< MARKED AS IGNORED: >=-
     
     Due to Oracle license restrictions, you must fetch the source 
     distribution manually.  Please access  
     http://www.oracle.com/technology/software/tech/oci/instantclient/index.html 
     with a web browser and follow the link for the 
     "instantclient-sdk-linux32-10.2.0.3-20061115.zip".  
     You will be required to register and log in, 
     but you can create an account on that page.  
     After registration and accepting the Oracle License, 
     download the distribution file, 
     instantclient-sdk-linux32-10.2.0.3-20061115.zip, 
     into /usr/ports/distfiles/oracle/ 
     and then restart this installation
    
    .*** Error code 1
    
    Stop in /usr/ports/databases/linux-oracle-instantclient-sdk.
    
  3. Follow the port's advice. Get the specified version of the Oracle Instant Client Basic for Linux and your system's processor architecture (32-bit or 64-bit). Don't download the latest version. Version numbers in the Makefile are hardcoded.
    
    [cheshire] databases% cd /usr/ports/distfiles
    [cheshire] distfiles% sudo mkdir oracle
    [cheshire] distfiles% cd oracle
    [cheshire] oracle% sudo mv /tmp/instantclient-basic-linux32-10.2.0.3-20061115.zip .
    [cheshire] oracle% sudo mv /tmp/instantclient-sdk-linux32-10.2.0.3-20061115.zip .
    
    
  4. FreeBSD used to support a port that built the PHP5 OCI8 extension. But now that port is only available for the aged PHP 5.2 revision (see databases/php52-oci8). So try this. Rebuild PHP with the OCI8 extension.
    1. Modify your PHP5 port's Makefile:
      
      % cd /usr/ports/lang/php5/
      % sudo vi Makefile
      
      Modify the CONFIGURE_ARGS options. Add:
      
      --with-oci8=shared,instantclient,/usr/compat/linux/usr/lib/oracle/10.2.0.3/client/lib \
      
      
    2. Rebuild PHP5 by forcing an upgrade of the package even if it is to be a reinstall of the same version (but with updated Makefile config args).
      
      % sudo portupgrade -f php5
      
      

References

  1. http://php.net/manual/en/oci8.installation.php
  2. http://www.oracle.com/technetwork/database/features/oci/index.html
  3. http://mrtenente.infosys.lt/blog/?p=22
  4. http://lists.freebsd.org/pipermail/freebsd-questions/2011-July/231739.html