Installing the Oracle Call Interface (OCI8) Module for PHP
This extension allows you to access Oracle databases using the Oracle Call Interface (OCI8).
Hotwire now ships with this module pre-compiled for your convenience, however we'll describe how you can recompile oci8 for some reason.
There are many ways to go about this, one way we'll consider here is to compile oci8 as a module (as opposed to building it into php5) as it is easier and allows for redistribution, independent of the installed PHP.
Stop!
Things just got a whole lot easier, get all the packages you need for RHEL 4 and RHEL 5 direct from Oracle OSS.
Quick Oracle 10g & PHP 5 Howto
- Install the following packages...
Red Hat Debian Notes php-pear php-pear for pear or pecl php5-dev php-devel for phpize automake, autoconf, libtool automake, autoconf, libtool for phpize (aclocal)
- Decide on your source directory...
SRC=/usr/local/src/oracle
- Prepare the work-area...
mkdir -p ${SRC}/oracle-oci8 mkdir -p ${SRC}/php5-oci8
- Download the oci8 libraries and header files to ${SRC}/oracle-oci8 from Oracle
- Get instantclient-basic for your architecture (not basiclite)
- Get instantclient-sdk for your architecture
- Install from source (.zip)...
cd ${SRC} unzip "${SRC}/oracle-oci8/instantclient-*.zip" cd instantclient_10_2 ln -s libclntsh.so.10.1 libclntsh.so
- Check it's all ok...
ldd *.so.10.1 ldd *.so
- Install from source (.rpm)...
cd ${SRC} mkdir instantclient_11_1 cd instantclient_11_1 ln -s /usr/include/oracle/11.1.0.1/client64/ include ln -s /usr/lib/oracle/11.1.0.1/client64/lib/ lib cd -
- Download the oci8 module for php and compile...
#! cd ${SRC}/php5-oci8 pear config-set http_proxy $http_proxy pecl download oci8 || pear download oci8 tar -szxvf oci8*.tgz cd oci8-${VER} phpize #. If oracle-instant-client zip install... ./configure --with-oci8=shared,instantclient,${SRC}/instantclient_10_2 #. if oracle-instant-client rpm install... ./configure --with-oci8=shared,instantclient,${SRC}/instantclient_11_1/lib make make install- Make sure the oci8.so module is in place, see the FAQ if you stumble.
- Cleanup...
rm -rf autom4te.cache config.cache; ./buildconf --force;
- You may wish to remove the development packages now that you no longer require them...
dpkg -P autoconf automake1.4 autotools-dev libtool php5-dev shtool
- Configure php to use this module; locate your distribution's php.ini file and edit...
- Add extension=oci8.so
- Amend log_errors = On
- Amend display_errors = Off
- Amend error_log = /var/log/php.log
- Restart Apache
- Check /var/log/php.log. If you have an error like the following, see this
PHP Warning: Unknown(): Unable to load dynamic library '/usr/lib64/php4/oci8.so' - /usr/lib64/php4/oci8.so: undefined symbol: zend_strtod in Unknown on line 0
- Make sure PHP sees oci8...
echo '<? phpinfo() ?>' > ${WWW_ROOT}/phpinfo.php
- View that page via your web browser and make sure there is an oci8 section.
Example Installations
RHEL5-Server, HP-Proliant-DL385, Oracle Database
Because this is going to be back-ended to Oracle, there will a set of additional work that will have to be carried out.
Firstly, we need some development tools (which can later be removed)...
# yum install subversion dhcp php-devel gcc ... #
Next, we checkout Symfony v1.1...
# mkdir /opt/symfony # cd /opt/symfony # svn co https://svn.symfony-project.com/branches/1.1 symfony-1.1 ... # ln -s symfony-1.1/ symfony
Next, we can install the hotwire packages, that step has been skipped (simply install the RPMs and their respective dependencies. After installation, the first thing you need to do is edit /etc/hotwire/hotwire.conf and set all the values as appropriate for your environment.
# vi /etc/hotwire/hotwire.conf
To verify the syntax...
# hw-chkconf -vv ... #
Next, mount your software repository that contains all the ISO images for Hotwire. Hotwire will tell you what paths it expects to find so you can worry about that later.
# mkdir -p /srv/hotwire-irbd/iso.d # mount /srv/hotwire-irbd/iso.d #
Next, obtain the two RPMs from Oracle and install...
# rpm -i /software/Oracle/OCI/oracle-instantclient-basic-11.1.0.1-1.x86_64.rpm # rpm -ql oracle-instantclient-basic-11.1.0.1 /usr/lib/oracle/11.1.0.1/client64/bin/adrci /usr/lib/oracle/11.1.0.1/client64/bin/genezi /usr/lib/oracle/11.1.0.1/client64/lib/libclntsh.so.11.1 /usr/lib/oracle/11.1.0.1/client64/lib/libnnz11.so /usr/lib/oracle/11.1.0.1/client64/lib/libocci.so.11.1 /usr/lib/oracle/11.1.0.1/client64/lib/libociei.so /usr/lib/oracle/11.1.0.1/client64/lib/libocijdbc11.so /usr/lib/oracle/11.1.0.1/client64/lib/ojdbc5.jar /usr/lib/oracle/11.1.0.1/client64/lib/ojdbc6.jar
# rpm -i /software/Oracle/OCI/oracle-instantclient-devel-11.1.0.1-1.x86_64.rpm # rpm -ql oracle-instantclient-devel-11.1.0.1/usr/include/oracle/11.1.0.1/client64/nzerror.h /usr/include/oracle/11.1.0.1/client64/nzt.h /usr/include/oracle/11.1.0.1/client64/occi.h /usr/include/oracle/11.1.0.1/client64/occiAQ.h /usr/include/oracle/11.1.0.1/client64/occiCommon.h /usr/include/oracle/11.1.0.1/client64/occiControl.h /usr/include/oracle/11.1.0.1/client64/occiData.h /usr/include/oracle/11.1.0.1/client64/occiObjects.h /usr/include/oracle/11.1.0.1/client64/oci.h /usr/include/oracle/11.1.0.1/client64/oci1.h /usr/include/oracle/11.1.0.1/client64/oci8dp.h /usr/include/oracle/11.1.0.1/client64/ociap.h /usr/include/oracle/11.1.0.1/client64/ociapr.h /usr/include/oracle/11.1.0.1/client64/ocidef.h /usr/include/oracle/11.1.0.1/client64/ocidem.h /usr/include/oracle/11.1.0.1/client64/ocidfn.h /usr/include/oracle/11.1.0.1/client64/ociextp.h /usr/include/oracle/11.1.0.1/client64/ocikpr.h /usr/include/oracle/11.1.0.1/client64/ocixmldb.h /usr/include/oracle/11.1.0.1/client64/odci.h /usr/include/oracle/11.1.0.1/client64/oratypes.h /usr/include/oracle/11.1.0.1/client64/ori.h /usr/include/oracle/11.1.0.1/client64/orid.h /usr/include/oracle/11.1.0.1/client64/orl.h /usr/include/oracle/11.1.0.1/client64/oro.h /usr/include/oracle/11.1.0.1/client64/ort.h /usr/include/oracle/11.1.0.1/client64/xa.h /usr/lib/oracle/11.1.0.1/client64/lib/libclntsh.so /usr/lib/oracle/11.1.0.1/client64/lib/libocci.so /usr/lib/oracle/11.1.0.1/client64/lib/ottclasses.zip /usr/share/oracle/11.1.0.1/client64/cdemo81.c /usr/share/oracle/11.1.0.1/client64/demo.mk /usr/share/oracle/11.1.0.1/client64/occidemo.sql /usr/share/oracle/11.1.0.1/client64/occidemod.sql /usr/share/oracle/11.1.0.1/client64/occidml.cpp /usr/share/oracle/11.1.0.1/client64/occiobj.cpp /usr/share/oracle/11.1.0.1/client64/occiobj.typ /usr/share/oracle/11.1.0.1/client64/ott
# mkdir /opt/oci
# cd /opt/oci/
# pear config-set http_proxy http://proxy.private.company.com.au:80/
config-set succeeded
# pecl download oci8
downloading oci8-1.3.5.tgz ...
Starting to download oci8-1.3.5.tgz (137,987 bytes)
.....done: 137,987 bytes
File /opt/oci/oci8-1.3.5.tgz downloaded
# ls
oci8-1.3.5.tgz
# tar -szxf oci8*.tgz
# cd oci8-1.3.5
# phpize
...
#
# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.1.0.1/client64/lib/
...
checking for egrep... 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 ANSI C... 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... 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
checking for PHP extension directory... /usr/lib64/php/modules
checking for PHP installed headers prefix... /usr/include/php
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... gawk
checking for Oracle (OCI8) support... yes, shared
checking PHP version... 5.1.6, ok
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... 8
checking checking if we're on a 64-bit platform... yes
checking Oracle Instant Client directory... /usr/lib/oracle/11.1.0.1/client64/lib/
checking Oracle Instant Client SDK header directory... /usr/include/oracle/11.1.0.1/client64
checking Oracle Instant Client version... 11.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... yes
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... 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 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... no
checking for fort... no
checking for xlf95... no
checking for ifc... no
checking for efc... no
checking for pgf95... no
checking for lf95... no
checking for gfortran... 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 -m elf_x86_64) 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
[root@uc-linux-1 oci8-1.3.5]# make
/bin/sh /opt/oci/oci8-1.3.5/libtool --mode=compile gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8.c -o oci8.lo
mkdir .libs
gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8.c -fPIC -DPIC -o .libs/oci8.o
/opt/oci/oci8-1.3.5/oci8.c: In function 'php_oci_do_connect_ex':
/opt/oci/oci8-1.3.5/oci8.c:1788: warning: cast from pointer to integer of different size
/opt/oci/oci8-1.3.5/oci8.c:2015: warning: cast to pointer from integer of different size
/bin/sh /opt/oci/oci8-1.3.5/libtool --mode=compile gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_lob.c -o oci8_lob.lo
gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_lob.c -fPIC -DPIC -o .libs/oci8_lob.o
/bin/sh /opt/oci/oci8-1.3.5/libtool --mode=compile gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_statement.c -o oci8_statement.lo
gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_statement.c -fPIC -DPIC -o .libs/oci8_statement.o
/bin/sh /opt/oci/oci8-1.3.5/libtool --mode=compile gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_collection.c -o oci8_collection.lo
gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_collection.c -fPIC -DPIC -o .libs/oci8_collection.o
/bin/sh /opt/oci/oci8-1.3.5/libtool --mode=compile gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_interface.c -o oci8_interface.lo
gcc -I. -I/opt/oci/oci8-1.3.5 -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -c /opt/oci/oci8-1.3.5/oci8_interface.c -fPIC -DPIC -o .libs/oci8_interface.o
/bin/sh /opt/oci/oci8-1.3.5/libtool --mode=link gcc -DPHP_ATOM_INC -I/opt/oci/oci8-1.3.5/include -I/opt/oci/oci8-1.3.5/main -I/opt/oci/oci8-1.3.5 -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/oracle/11.1.0.1/client64 -DHAVE_CONFIG_H -g -O2 -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /opt/oci/oci8-1.3.5/modules oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/usr/lib/oracle/11.1.0.1/client64/lib/ -L/usr/lib/oracle/11.1.0.1/client64/lib/ -lclntsh
gcc -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.1.0.1/client64/lib/ -lclntsh -Wl,-rpath -Wl,/usr/lib/oracle/11.1.0.1/client64/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 /opt/oci/oci8-1.3.5/libtool --mode=install cp ./oci8.la /opt/oci/oci8-1.3.5/modules
cp ./.libs/oci8.so /opt/oci/oci8-1.3.5/modules/oci8.so
cp ./.libs/oci8.lai /opt/oci/oci8-1.3.5/modules/oci8.la
PATH="$PATH:/sbin" ldconfig -n /opt/oci/oci8-1.3.5/modules
----------------------------------------------------------------------
Libraries have been installed in:
/opt/oci/oci8-1.3.5/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.
(It is safe to ignore warnings about tempnam and tmpnam).
Now you can install the OCI module...
# make install Installing shared extensions: /usr/lib64/php/modules/
Make sure PHP knows about it...
# vi /etc/php.d/oci.ini
And test your configuration again...
# hw-chkconf -vv
If it's valid, push it into the active configuration...
# hw-chkconf -c
Now the final step, which also checks that everything is ok...
# hotwire init * Checking `hotwire.conf' syntax...Good * Checking for `autofs_conf'...Good * Checking for `autofs_d'...Good * Checking for `csv_d'...Good * Checking for `tftp_root' and internals...Good * Checking for `pxe_d' and internals...Good * Checking `pxelinux.cfg'...Good * Checking for `iso_d'...Good * Checking for `ssl_d'...Good * Amending Symfony configuration...Done * Amending Symfony Propel Configuration...Done * Amending Symfony Database Configuration...Done * Checking for the symfony framework...Good * Fixing Permissions.........Done * Testing for PHP OCI module...Done @ Testing Database Connectivity...PASSED * Verifying private virtualhost...Done (Valid Name) * Verifying public virtualhost...Done (Valid Name) * Amending `/var/lib/hotwire/apache.conf'...Skipped * Execution time: 3s #
We're almost ready to go; Now we have to make sure PHP has at least 64M of memory, so set memory_limit = 64M in /etc/php.ini, and restart Apache.
Now prepare the new database...
# hotwire propel-model-build ... # hotwire db-recreate ...
...and you're done.
