Home > centOS, Fedora 12, PHP, Zend > CentOS oracle php database connect oci instantclient oci8

CentOS oracle php database connect oci instantclient oci8

* Go Centos 5.4
* Tips: http://www.oracle.com/technology/pub/notes/technote_php_instant.html

1. RPM for i386 download: http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html

[root@www Desktop]# rmp -Uvh oracle-instantclient11.2-basic-11.2.0.1.0-1.i386.rpm
-bash: rmp: command not found
[root@www Desktop]# rpm -Uvh oracle-instantclient11.2-basic-11.2.0.1.0-1.i386.rpm
Preparing...                ########################################### [100%]
 1:oracle-instantclient11.########################################### [100%]
[root@www Desktop]# rpm -Uvh oracle-instantclient11.2-devel-11.2.0.1.0-1.i386.rpm
Preparing...                ########################################### [100%]
 1:oracle-instantclient11.########################################### [100%]
[root@www Desktop]#


2. Install oci8.so using pecl

[root@www phpoci]# pecl install oci8
WARNING: channel "pecl.php.net" has updated its protocols, use "channel-update pecl.php.net" to update
downloading oci8-1.4.1.tgz ...
Starting to download oci8-1.4.1.tgz (149,097 bytes)
.................................done: 149,097 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
 1. 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

1-1, 'all', 'abort', or Enter to continue:
building in /var/tmp/pear-build-root/oci8-1.4.1
running: /var/tmp/oci8/configure --with-oci8

checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
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 cc accepts -g... yes
checking for cc option to accept ANSI C... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-redhat-linux-gnu
checking host system type... i686-redhat-linux-gnu
checking target system type... i686-redhat-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for Oracle (OCI8) support... yes, shared
checking PHP version... 5.2.13, ok
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 checking if we're on a 64-bit platform... no
configure: WARNING: OCI8 extension: ORACLE_HOME is not set, looking for default Oracle Instant Client instead
checking Oracle Instant Client directory... /usr/lib/oracle/11.2/client/lib
checking Oracle Instant Client SDK header directory... /usr/include/oracle/11.2/client
checking Oracle Instant Client version... 11.1
checking for ld used by cc... /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... yes
checking for dlfcn.h... yes
checking for g77... no
checking for f77... no
checking for xlf... no
checking for frt... no
checking for pgf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for f90... no
checking for xlf90... no
checking for pgf90... no
checking for epcf90... no
checking for f95... f95
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether f95 accepts -g... yes
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc 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
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for f95 option to produce PIC... -fPIC
checking if f95 PIC flag -fPIC works... yes
checking if f95 static flag -static works... yes
checking if f95 supports -c -o file.o... yes
checking whether the f95 linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8.c -o oci8.lo
mkdir .libs
 cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8.c  -fPIC -DPIC -o .libs/oci8.o
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_lob.c -o oci8_lob.lo
 cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_lob.c  -fPIC -DPIC -o .libs/oci8_lob.o
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_statement.c -o oci8_statement.lo
 cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_statement.c  -fPIC -DPIC -o .libs/oci8_statement.o
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_collection.c -o oci8_collection.lo
 cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_collection.c  -fPIC -DPIC -o .libs/oci8_collection.o
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_interface.c -o oci8_interface.lo
 cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_interface.c  -fPIC -DPIC -o .libs/oci8_interface.o
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=link cc -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.4.1/include -I/var/tmp/pear-build-root/oci8-1.4.1/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/include/oracle/11.2/client  -DHAVE_CONFIG_H  -g -O2   -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root/oci8-1.4.1/modules  oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/usr/lib/oracle/11.2/client/lib -L/usr/lib/oracle/11.2/client/lib -lclntsh
cc -shared  .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o  -L/usr/lib/oracle/11.2/client/lib -lclntsh  -Wl,-rpath -Wl,/usr/lib/oracle/11.2/client/lib -Wl,-soname -Wl,oci8.so -o .libs/oci8.so
creating oci8.la
(cd .libs && rm -f oci8.la && ln -s ../oci8.la oci8.la)
/bin/sh /var/tmp/pear-build-root/oci8-1.4.1/libtool --mode=install cp ./oci8.la /var/tmp/pear-build-root/oci8-1.4.1/modules
cp ./.libs/oci8.so /var/tmp/pear-build-root/oci8-1.4.1/modules/oci8.so
cp ./.libs/oci8.lai /var/tmp/pear-build-root/oci8-1.4.1/modules/oci8.la
PATH="$PATH:/sbin" ldconfig -n /var/tmp/pear-build-root/oci8-1.4.1/modules
----------------------------------------------------------------------
Libraries have been installed in:
 /var/tmp/pear-build-root/oci8-1.4.1/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
 - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
 during execution
 - add LIBDIR to the `LD_RUN_PATH' environment variable
 during linking
 - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
 - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-oci8-1.4.1" install
Installing shared extensions:     /var/tmp/pear-build-root/install-oci8-1.4.1/usr/lib/php/modules/
running: find "/var/tmp/pear-build-root/install-oci8-1.4.1" | xargs ls -dils
12223692   8 drwxr-xr-x 3 root root   4096 Apr 12 20:23 /var/tmp/pear-build-root/install-oci8-1.4.1
12223721   8 drwxr-xr-x 3 root root   4096 Apr 12 20:23 /var/tmp/pear-build-root/install-oci8-1.4.1/usr
12223722   8 drwxr-xr-x 3 root root   4096 Apr 12 20:23 /var/tmp/pear-build-root/install-oci8-1.4.1/usr/lib
12223723   8 drwxr-xr-x 3 root root   4096 Apr 12 20:23 /var/tmp/pear-build-root/install-oci8-1.4.1/usr/lib/php
12223724   8 drwxr-xr-x 2 root root   4096 Apr 12 20:23 /var/tmp/pear-build-root/install-oci8-1.4.1/usr/lib/php/modules
12223720 412 -rwxr-xr-x 1 root root 412686 Apr 12 20:23 /var/tmp/pear-build-root/install-oci8-1.4.1/usr/lib/php/modules/oci8.so

Build process completed successfully
Installing '/usr/lib/php/modules/oci8.so'
install ok: channel://pecl.php.net/oci8-1.4.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini
[root@www phpoci]#

3. vi /etc/php.ini , add the line

extention=oci8.so

4. Add the path of rpm installed directory

[root@www lib]# export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client/lib
[root@www lib]# echo $LD_LIBRARY_PATH
/usr/lib/oracle/11.2/client/lib

5. Restart the apachectl

[root@www lib]# /usr/sbin/apachectl restart
[Mon Apr 12 20:33:59 2010] [warn] module php5_module is already loaded, skipping
[root@www lib]#

6. Test it

<?php
 function db_connect($un = ORA_CON_UN, $pw = ORA_CON_PW){
 $conn = oci_connect($un, $pw, 'localhost/XE');
 if (!$conn) {
 echo "Connection failed.. \n" ;
 return false;
 }else{
 echo "Connected... \n";
 }
 return($conn);
 }

 db_connect('system','mypassword');
?>

[oracle@www tmp]$ php db.php
Connected...
[oracle@www tmp]$

Done.

Advertisements
Categories: centOS, Fedora 12, PHP, Zend
  1. anonuser
    November 9, 2010 at 2:00 am

    Thanks for the info.

    Just one thing extention=oci8.so should be extension=oci8.so which caught me out being a lazy cut and paster :).

  2. Jerry
    May 27, 2011 at 9:03 pm

    I still cannot install in spite of this nice document =(

    ERROR: `/var/tmp/oci8/configure –with-oci8=instantclient,/path/to/instant/client/lib’ failed

    [jlau@myserver oracle]$ sudo pecl install oci8
    downloading oci8-1.4.5.tgz …
    Starting to download oci8-1.4.5.tgz (154,284 bytes)
    ………………done: 154,284 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,/path/to/instant/client/lib
    building in /var/tmp/pear-build-rootrEZul1/oci8-1.4.5
    running: /var/tmp/oci8/configure –with-oci8=instantclient,/path/to/instant/client/lib
    checking for egrep… grep -E
    checking for a sed that does not truncate output… /bin/sed
    checking for cc… cc
    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 cc accepts -g… yes
    checking for cc option to accept ANSI C… none needed
    checking how to run the C preprocessor… cc -E
    checking for icc… no
    checking for suncc… no
    checking whether cc understands -c and -o together… yes
    checking for system library directory… lib
    checking if compiler supports -R… no
    checking if compiler supports -Wl,-rpath,… yes
    checking build system type… x86_64-redhat-linux-gnu
    checking host system type… x86_64-redhat-linux-gnu
    checking target system type… x86_64-redhat-linux-gnu
    checking for PHP prefix… /usr
    checking for PHP includes… -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
    checking for PHP extension directory… /usr/lib64/php/modules
    checking for PHP installed headers prefix… /usr/include/php
    checking if debug is enabled… no
    checking if zts is enabled… no
    checking for re2c… no
    configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
    checking for gawk… gawk
    checking for Oracle (OCI8) support… yes, shared
    checking PHP version… 5.2.17, ok
    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… 8
    checking checking if we’re on a 64-bit platform… yes
    checking Oracle Instant Client directory… /path/to/instant/client/lib
    checking Oracle Instant Client SDK header directory… configure: error: Oracle Instant Client SDK header files not found
    ERROR: `/var/tmp/oci8/configure –with-oci8=instantclient,/path/to/instant/client/lib’ failed

  3. March 14, 2012 at 3:21 am

    via command line
    [root@cnr2 html]# php oci.php
    PHP Warning: Module ‘oci8’ already loaded in Unknown on line 0

    Warning: Module ‘oci8’ already loaded in Unknown on line 0
    Connected…
    [root@cnr2 html]#

    and here its, i try browse the code
    Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories in /var/www/html/oci.php on line 3

    Warning: oci_connect() [function.oci-connect]: Error while trying to retrieve text for error ORA-01804 in /var/www/html/oci.php on line 3
    Connection failed..

    how to set environment variable ORACLE_HOME and LD_LIBRARY_PATH on centos

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: