Setting up PHP to use Oracle Instant Client (oci8) under RHEL/Fedora/CentOS distributions

Published on
26,792 Points
Last Modified:
Michael Worsham
Well-rounded and highly experienced with a professional background in cloud/infrastructure solutions and project management.
Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal time and effort.

To complete the steps, you you will need to get the Oracle Instant Client and the OCI8 PECL package.

Oracle Instant Client: http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html
PECL OCI8 Package: http://pecl.php.net/package/oci8

1) Install Apache, PHP, the Oracle Instant Client MySQL support if you want it and required development packages to build from source code.

    yum install httpd php php-mysql php-pear php-devel zlib zlib-devel
    yum groupinstall "Development Tools"

2) Add the Oracle instant client to dynamic linker

    echo /usr/include/oracle/ON>/client > /etc/ld.so.conf.d/oracle_client.conf
    ldconfig -v

3) Untar the PECL package and prepare it for compiling

    tar -xzvf oci-.tgz
    cd oci-

4) Configure the PECL package as a shared object using the instant client and specifying where the Oracle client libraries are. Then build and install it.

    ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/N>/client/lib
    make install

5) Add the library shared object for PHP

    echo extension=oci8.so > /etc/php.d/oci8.ini

6) Start Apache

    'service httpd start' _or_ '/etc/init.d/httpd restart'

7) Create a PHP info page and checked to see if the Oracle (oci8) driver is listed:

    echo  > /var/www/html/phpinfo.php
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free