Install OCI8 on CentOS/Redhat/Fedora

Install OCI8 on CentOS/Redhat/Fedora

The post will describe how to Install OCI8 on CentOS/Redhat/Fedora in step by step. The easiest way to configure PHP to access Oracle Database is to use Oracle Instant Client libraries. This note describes how to install PHP with the OCI8 Extension and Oracle Instant Client on CentOS/Redhat/Fedora. OCI8 is the PHP extension for connecting to Oracle Database. You need to install two packages: oracle-instant-client and php oci8 extension. It is assumed that PHP with pecl package is installed in your server

  1. Check your server architecture and OS version
    # uname -a
    Linux localhost 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST
    2011 x86_64 x86_64 x86_64 GNU/Linux

    el6 means it is enterprise linux 6 and x86_64 means it is 64 bit machine. For 32 bit machine it would be i386

  2. Download two RPM packages: oracle-instantclient basic and oracle-instantclient devel from instant client downloads page .
    Here you need to choose “Instant Client for Linux x86_64”. For 32 bit machine you should select “Instant Client for Linux x86”.
    Download red tick instant client basic RPM package.
    instantclient_basicScroll down and download red tick instant client devel rpm package.
    instantclient_devel
  3. Install the RPMs as the root user
    # rpm -Uvh oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64.rpm
    Preparing...                ########################################### [100%]
       1:oracle-instantclient12.########################################### [100%]
    # rpm -Uvh oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64.rpm
    Preparing...                ########################################### [100%]
       1:oracle-instantclient12.########################################### [100%]

    The instantclient library and executable files are generally installed on /usr/lib/oracle/12.1/client64/ for 64 bit machine and on /usr/lib/oracle/12.1/client/ for 32 machine

  4. Set environment variables ORACLE_HOME and LD_LIBRARY_PATH
    # ORACLE_HOME=/usr/lib/oracle/12.1/client64; export ORACLE_HOME
    # LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH

    You should also add the above two lines in ~/.bash_profile file. Edit the file by vi editor and add the lines above PATH=$PATH:$HOME/bin

    #vim  ~/.bash_profile

    After edited the file would be

  5. Check you have php-pear and php-devel packages installed by this command. You must have these package installed
    # rpm -qa | grep -i php
    php-5.3.3-3.el6_1.3.x86_64
    php-cli-5.3.3-3.el6_1.3.x86_64
    php-devel-5.3.3-3.el6_1.3.x86_64
    php-common-5.3.3-3.el6_1.3.x86_64
    php-mysql-5.3.3-3.el6_1.3.x86_64
    php-soap-5.3.3-3.el6_1.3.x86_64
    php-pear-1.9.4-4.el6.noarch
    php-gd-5.3.3-3.el6_1.3.x86_64
  6. Install oci8 extension
    # pecl install oci8

    You will be asked to provide instantclient library path and so provide the instant cleint library path just you installed( put instantclient then coma then library path)

    Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :instantclient,/usr/lib/oracle/12.1/client64/lib

    After pressing enter ,at the end portion you will see the line “Build process completed successfully”

    Build process completed successfully
    Installing '/usr/lib64/php/modules/oci8.so'
    install ok: channel://pecl.php.net/oci8-2.0.6
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=oci8.so" to php.ini
  7. Add “extension=oci8.so” to /etc/php.ini file just below the [PHP] line and it would like
    [PHP]
    extension=oci8.so
    ;;;;;;;;;;;;;;;;;;;
    ; About php.ini   ;
    ;;;;;;;;;;;;;;;;;;;
    ; PHP's initialization file, generally called php.ini, is responsible for
    ; configuring many of the aspects of PHP's behavior.
  8. Restart Web Server(Apache or Nginx)
    # /etc/init.d/httpd restart
  9. Now check oci8 extension is installed and OCI8 Support is enabled

The above procedure regarding “Install OCI8 on CentOS/Redhat/Fedora” should work for major version of Linux distribution

 



One thought on “Install OCI8 on CentOS/Redhat/Fedora

Comments are closed.