The PHP "./configure --with-oci8" Option in Detail

When PHP is built from source code on Linux, the typical build steps are:


tar -xjf php-5.2.9.tar.bz2
cd php-5.2.9
./configure --with-your-desired-extensions
make
make test
make install

The "configure" stage creates the appropriate makefile to build all the extensions you want. Specify the --help option to list all the many build configurations available.

To build PHP with the OCI8 extension, use the --with-oci8 option:


./configure --with-oci8 ...

OCI8 needs to link with Oracle libraries which handle communication to the database. The main choice when building the OCI8 extension depends on what Oracle libraries you have installed.

PHP OCI8 can be built using libraries from a full Oracle Database (or Database "Client") install, created from running the GUI installer. This is often referred to as an "ORACLE_HOME" install, since an environment variable of that name is set to the installed Oracle software directory.

Alternatively PHP OCI8 can be built using the free Oracle Instant Client, installed from zip files or RPMs. If you are building with Oracle Instant Client you almost certainly should not have the ORACLE_HOME environment variable set. Only set ORACLE_HOME if you have a full Oracle install.

Another dimension to the install is that PHP extensions can be statically compiled into the PHP executable(s), or built as shared binaries. If OCI8 is built as a shared library it is loaded into PHP as a result of setting the php.ini option "extension=oci8.so". Building shared extensions like this makes it easy to upgrade one extension without affecting the rest of PHP.

The list below describes how to use the --with-oci8 option.


  1. --with-oci8

    Looks for Oracle Database libraries in $ORACLE_HOME, which must previously have been set.

    Links the oci8 extension statically into the php executable(s)

    I just merged an enhancement that if $ORACLE_HOME is not set, will then look for the Instant Client RPM libraries. This patch will appear in PHP 5.3 and the future PECL OCI8 1.3.5.


  2. --with-oci8=/path/to/full/oracle/home

    Same as #1, but uses the specified path instead of de-referencing $ORACLE_HOME.


  3. --with-oci8=shared

    Same as #1, but creates an oci8.so shared library.


  4. --with-oci8=shared,/path/to/full/oracle/home

    Like #2 and #3 combined: uses the specified Oracle Database libraries and creates a shared oci8.so extension.


  5. --with-oci8=instantclient

    Looks for Oracle Instant Client RPMs and uses the most recent version installed.

    Links the oci8 extension statically into the php executable(s).


  6. --with-oci8=instantclient,/path/to/instantclient/libs

    Like #5, but uses the Instant Client in the specified directory.


  7. --with-oci8=shared,instantclient

    Like #5, but builds a shared oci8.so extension.


  8. --with-oci8=shared,instantclient,/path/to/instantclient/libs

    Like #6 and #7 combined: uses the specified Instant Client and creates a shared oci8.so extension.


In a future blog post I will talk about the options for installing from PECL, which is useful for adding OCI8 to an existing PHP install.

Comments:

Really appreciate you putting this stuff out there! Where does one look to find the latest "best" practices for PHP and Oracle? Not knowing much about Oracle, I am trying to get php 5.2 to talk OCI8 with a full-blown Oracle 11gR2 OSEE. I am going to use this "--with-oci8" option and see where that gets me. Is this generally better than MDB2 (PEAR)?

Posted by Charles Schultz on July 02, 2010 at 03:58 AM PDT #

OCI8 is more low level than MDB2 and has a control & performance benefit. However abstraction layers and frameworks have become very popular for PHP development because of the facilities they provide. This blog is a good source of best practices. Also check out the free book http://www.oracle.com/technology/tech/php/underground-php-oracle-manual.html

Posted by christopher.jones on July 02, 2010 at 04:06 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

Tourists looking out over an Opal mine
I'm a Product Manager in Server Technologies, working on scripting languages and developer-access.
Email: christopher.jones@oracle.com
Twitter: http://twitter.com/ghrd
Book: Free PHP Oracle book
Download: PHP Linux RPMs with the OCI8 extension
Links: OTN PHP Developer Center

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today