preload preload


[How-To] Install PHP OCI8 extension

If you are looking to connect the PHP to an oracle database, you would require to install PHP OCI8 extension. Following instructions will explain you the installation of PHP OCI8 extension using PECL on CentOS 5.5 64-bit server. We assume you already have installed the PEAR extension for PHP.

1. First install the Oracle Instant client on your server.

yum install oracle-instantclient-basic
yum install oracle-instantclient-devel

2. The above command will install Oracle Instant Client library in /usr/lib64/oracle/<version>/client/lib and Oracle Instant Client SDK header files in /usr/include/oracle/<version>/client.

3. This above folder layout is a problem for PHP OCI8 extension installation because the “./configure –with-oci8=shared,instantclient,/path/to/instantclient/lib” will look for the Oracle Instant Client SDK header filed in the same library folder i.e. /usr/lib64/oracle/<version>/client folde in our case and since the location of SDK header files are different hence it will raise the following error:


checking Oracle Instant Client SDK header directory... configure: error: Oracle Instant Client SDK header files not found

A quick glance at the source code of PHP OCI8 extension (config.m4) reveals that it specifically looks for the include folder in the Oracle Instant Client library as one of the option as following


AC_MSG_CHECKING([Oracle Instant Client SDK header directory])

 dnl Header directory for Instant Client SDK RPM install
 OCISDKRPMINC=`echo "$PHP_OCI8_INSTANT_CLIENT" | $PHP_OCI8_SED -e 's!^/usr/lib/oracle/\(.*\)/client\('${PHP_OCI8_IC_LIBDIR_SUFFIX}'\)*/lib[/]*$!/usr/include/oracle/\1/client\2!'`

 dnl Header directory for Instant Client SDK zip file install
 OCISDKZIPINC=$PHP_OCI8_INSTANT_CLIENT/sdk/include

 dnl Header directory for manual installation
 OCISDKMANINC=`echo "$PHP_OCI8_INSTANT_CLIENT" | $PHP_OCI8_SED -e 's!\(.*\)/lib[/]*$!\1/include!'`

 if test -f "$OCISDKRPMINC/oci.h"; then
 AC_MSG_RESULT($OCISDKRPMINC)
 PHP_ADD_INCLUDE($OCISDKRPMINC)
 OCI8INCDIR=$OCISDKRPMINC
 elif test -f "$OCISDKZIPINC/oci.h"; then
 AC_MSG_RESULT($OCISDKZIPINC)
 PHP_ADD_INCLUDE($OCISDKZIPINC)
 OCI8INCDIR=$OCISDKZIPINC
 elif test -f "$OCISDKMANINC/oci.h"; then
 AC_MSG_RESULT($OCISDKMANINC)
 PHP_ADD_INCLUDE($OCISDKMANINC)
 OCI8INCDIR=$OCISDKMANINC
 else
 AC_MSG_ERROR([Oracle Instant Client SDK header files not found])
 fi

To solve this issue, we will create a symlink for Oracle Instant Client SDK library path in the Oracle Instant Client library path like


ln -s /usr/include/oracle/<version>/client /usr/lib64/oracle/<version>/client/lib/include

Note: Please change <version> to your Oracle Instant Client version.

4. Now, we are ready to install the PHP OCI8 extension. Run the following commands to install PHP OCI8 extension.


pear download pecl/oci8

tar xvzf oci8-1.4.5.tgz

cd oci8-1.4.5

phpize

./configure --with-oci8=shared,instantclient,/usr/lib64/oracle/10.2.0.3/client/lib/

make all install

This will complete the installation of PHP OCI8 extension successfully. You can now move the extension oci8.so to your PHP extension directory.

Liked the content? Then why not share with your pals

  • 4 responses to "[How-To] Install PHP OCI8 extension"

  • Nitin
    20:02 on May 18th, 2011

    Hi, Thanks for the useful steps which worked for me, Just one correction

    when we execute ./configure command that time it failed for me. To overcome this i executed phpize before executing ./configure

  • Deepesh
    20:21 on May 18th, 2011

    @Nitin, thanks for heads up. That is a mandatory step.

  • nilmi
    10:34 on July 20th, 2011

    Hi, Thanks for the review. but i got problem when installing oci 8. i’ve tried the command “pear download pecl/oci8″ but then i’ve got this message : No releases available for package “pecl.php.net/oci8″
    Cannot initialize ‘pecl/oci8′, invalid or missing package file
    Package “pecl/oci8″ is not valid
    download failed

    then i tried another command “pear install pecl/oci8″ ,but then again i’ve got this message :
    No releases available for package “pecl.php.net/oci8″
    Cannot initialize ‘pecl/oci8′, invalid or missing package file
    Package “pecl/oci8″ is not valid
    install failed

    i have install php-pear before including the dependencies, so would you tell me what the eror is all about?
    i’m new in linux.. :)
    thanks

  • Deepesh
    20:03 on July 20th, 2011

    @nilmi, which version of php you are using. It might be the reason that either your pear is not installed properly or you need to reinitialize the pecl.php.net channel. Try to do the following commands

    pear channel-info pear.php.net

    It will show whether your channel is registered properly or not

  • Leave a Reply

    * Required
    ** Your Email is never shared