How to install oci8 for PHP 5 on Ubuntu

OCI8 is an extension for providing APIs to Oracle database management system. However, installing OCI8 is not just easy like apt-get since it requires SDK offered by Oracle and its distribution license prohibits the inclusion to linux distribution. That means we have to download and compile it by ourselves. Fortunately, it is a little bit easy for Ubuntu.

  1. Install PEAR and PECL

    sudo apt-get install php-pear
    
  2. Download Oracle Instant Client. You need at least Basic and SDK.

  3. Extract the archives.

    sudo mkdir -p /opt/oracle
    cd /opt/oracle
    sudo unzip instantclient-basic-linux-x86-64-10.2.0.3-20070103.zip
    sudo unzip instantclient-sdk-linux-x86-64-10.2.0.3-20070103.zip
    sudo mv /opt/oracle/instantclient_10_2 /opt/oracle/instantclient
    
  4. Create symbolic links.

    cd /opt/oracle/instantclient
    sudo ln -s libclntsh.so.10.1 libclntsh.so
    sudo ln -s libocci.so.10.1 libocci.so
    
  5. Add instant client to system ld.

    sudo su -
    echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient
    
  6. Compile oci8.

    sudo pecl install oci8
    
  7. Enter instantclient,/opt/oracle/instantclient when you are prompted.

  8. Enable the extension.

    sudo su -
    echo extension=oci8.so >> /etc/php5/apache2/php.ini
    
  9. Restart apache2.

    sudo /etc/init.d/apache2 restart
    

Tags: , , ,

compiling oci8

hi i'm new to using php with oracle and found your instructions really useful but i'm having problems with compiling oci8. "trying sudo pecl install oci8" always gives me the error "No releases available for package 'pecl.php.net/oci8' Cannot initialize 'oci8', invalid or missing package file Package 'oci8' is not valid". i've had a look around the web and they all give the same command for installing oci8 so i'm at a bit of a loss as to why i'm having this problem. i'd appreciate any help you can give me with this.

pecl and oci8

I recommend you to upgrade PECL and PHP since you may have an obsolete one. Otherwise, you might have to reinitialize the channel pecl.php.net again if channel-info gives failure result.

sudo pecl channel-info pecl.php.net

Compiling oci8 - phpize error

Hi, thanks for the excellent help on installing oci8. I am trying to compile on Kubuntu Feisty. When I go to compile, the compile stops when running phpize. Im new to linux and am not sure if I got the wrong .zip file perhaps? My pecl channel-info looks good. The error message: running: phpize sh: phpize: not found ERROR: `phpize' failed Any help would be 'preciated. Thanks

You might need the php5-dev

You might need the php5-dev package. sudo apt-get install php5-dev

sudo pecl install oci8/Compilling oci8

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] : autodetect building in /var/tmp/pear-build-root/oci8-1.3.3 running: /tmp/pear/cache/oci8-1.3.3/configure --with-oci8 checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc and cc understand -c and -o together... yes checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu checking for PHP prefix... /usr checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 checking for PHP extension directory... /usr/lib/php5/20060613+lfs checking for PHP installed headers prefix... /usr/include/php5 checking for re2c... no configure: WARNING: You will need re2c 0.9.11 or later if you want to regenerate PHP parsers. checking for gawk... no checking for nawk... nawk checking if nawk is broken... no checking for Oracle (OCI8) support... yes, shared checking PHP version... 5.2.0, ok checking Oracle Install Directory... checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for long int... yes checking size of long int... 4 checking if we're on a 64-bit platform... no checking OCI8 libraries dir... lib checking Oracle version... configure: error: Oracle client libraries not found ERROR: `/tmp/pear/cache/oci8-1.3.3/configure --with-oci8' failed debian:~# I am using Debian and logged on as root as I have no user account because it gets in my way. So I alwasy log on my pc as root. This is the error I get when trying to (sudo pecl install oci8) I also put in the path (instantclient,/opt/oracle/instantclient) and get this below: debian:~# sudo pecl install oci8 downloading oci8-1.3.3.tgz ... Starting to download oci8-1.3.3.tgz (127,320 bytes) .............................done: 127,320 bytes 10 source files, building running: phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 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,/opt/oracle/instantclient building in /var/tmp/pear-build-root/oci8-1.3.3 running: /tmp/pear/cache/oci8-1.3.3/configure --with-oci8=instantclient,/opt/oracle/instantclient checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc and cc understand -c and -o together... yes checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu checking for PHP prefix... /usr checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 checking for PHP extension directory... /usr/lib/php5/20060613+lfs checking for PHP installed headers prefix... /usr/include/php5 checking for re2c... no configure: WARNING: You will need re2c 0.9.11 or later if you want to regenerate PHP parsers. checking for gawk... no checking for nawk... nawk checking if nawk is broken... no checking for Oracle (OCI8) support... yes, shared checking PHP version... 5.2.0, ok checking for long int... yes checking size of long int... 4 checking Oracle Instant Client directory... /opt/oracle/instantclient checking Oracle Instant Client SDK header directory... /opt/oracle/instantclient/sdk/include checking Oracle Instant Client version... 10.1 checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for /usr/bin/ld option to reload object files... -r checking for BSD-compatible nm... /usr/bin/nm -B checking whether ln -s works... yes checking how to recognise dependent libraries... pass_all checking dlfcn.h usability... yes checking dlfcn.h presence... no configure: WARNING: dlfcn.h: accepted by the compiler, rejected by the preprocessor! configure: WARNING: dlfcn.h: proceeding with the compiler's result checking for dlfcn.h... yes checking for g++... no checking for c++... no checking for gpp... no checking for aCC... no checking for CC... no checking for cxx... no checking for cc++... no checking for cl.exe... no checking for FCC... no checking for KCC... no checking for RCC... no checking for xlC_r... no checking for xlC... no checking whether we are using the GNU C++ compiler... no checking whether g++ accepts -g... no checking for g77... no checking for xlf... no checking for f77... no checking for frt... no checking for pgf77... no checking for cf77... no checking for fort77... no checking for fl32... no checking for af77... no checking for xlf90... no checking for f90... no checking for pgf90... no checking for pghpf... no checking for epcf90... no checking for gfortran... no checking for g95... no checking for xlf95... no checking for f95... no checking for fort... no checking for ifort... no checking for ifc... no checking for efc... no checking for pgf95... no checking for lf95... no checking for ftn... no checking whether we are using the GNU Fortran 77 compiler... no checking whether accepts -g... no checking the maximum length of command line arguments... 32768 checking command to parse /usr/bin/nm -B output from gcc object... ok checking for objdir... .libs checking for ar... ar checking for ranlib... ranlib checking for strip... strip checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC checking if gcc PIC flag -fPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no configure: creating libtool appending configuration tag "CXX" to libtool appending configuration tag "F77" to libtool configure: creating ./config.status config.status: creating config.h running: make /bin/sh /var/tmp/pear-build-root/oci8-1.3.3/libtool --mode=compile gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8.c -o oci8.lo mkdir .libs gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8.c -fPIC -DPIC -o .libs/oci8.o /bin/sh /var/tmp/pear-build-root/oci8-1.3.3/libtool --mode=compile gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_lob.c -o oci8_lob.lo gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_lob.c -fPIC -DPIC -o .libs/oci8_lob.o /bin/sh /var/tmp/pear-build-root/oci8-1.3.3/libtool --mode=compile gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_statement.c -o oci8_statement.lo gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_statement.c -fPIC -DPIC -o .libs/oci8_statement.o /bin/sh /var/tmp/pear-build-root/oci8-1.3.3/libtool --mode=compile gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_collection.c -o oci8_collection.lo gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_collection.c -fPIC -DPIC -o .libs/oci8_collection.o /bin/sh /var/tmp/pear-build-root/oci8-1.3.3/libtool --mode=compile gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_interface.c -o oci8_interface.lo gcc -I. -I/tmp/pear/cache/oci8-1.3.3 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/oci8-1.3.3/oci8_interface.c -fPIC -DPIC -o .libs/oci8_interface.o /bin/sh /var/tmp/pear-build-root/oci8-1.3.3/libtool --mode=link gcc -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.3/include -I/var/tmp/pear-build-root/oci8-1.3.3/main -I/tmp/pear/cache/oci8-1.3.3 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/opt/oracle/instantclient/sdk/include -DHAVE_CONFIG_H -g -O2 -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root/oci8-1.3.3/modules oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/opt/oracle/instantclient -L/opt/oracle/instantclient -lclntsh gcc -shared .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o -L/opt/oracle/instantclient -lclntsh -Wl,-rpath -Wl,/opt/oracle/instantclient -Wl,-soname -Wl,oci8.so -o .libs/oci8.so /usr/bin/ld: skipping incompatible /opt/oracle/instantclient/libclntsh.so when searching for -lclntsh /usr/bin/ld: cannot find -lclntsh collect2: ld returned 1 exit status make: *** [oci8.la] Error 1 ERROR: `make' failed debian:~# So I have no idea as to what I have done wrong.

sudo is for users not logged

sudo is for users not logged in as root (super-user do), since you are the super-user you can leave that out.

Post new comment