8 May 2012

Instalasi Oracle Instanclient dan OCI8

follow article
 

Jika bekerja dengan PHP dan Oracle, kita memerlukan koneksi oci8. Artikel ini menjelaskan tahap demi tahap instalasi Orcale Instantclient dan OCI 8 di CentOS 6.

Instalasi oracle-instantclient RPM

Untuk instalasi oracle-instantclient, kita perlu mendownload dua file : oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm dan oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm di website oracle.

Setelah itu install file rpm tersebut melalui perintah :

rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:oracle-instantclient11.########################################### [100%]

rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:oracle-instantclient11.########################################### [100%]

Install OCI8

Instalasi OCI8 saya lakukan melalui perintah pecl. Agar perintah pecl dikenal, pastikan anda sudah menginstall php-pear. Dalam instalasi oci8 juga akan memanggil perintah phpize, agar perintah phpize ini dikenal, pastikan anda sudah menginstall php-devel. Di samping itu "Development Tools" juga perlu diinstall terlebih dahulu. Semua langkah ini sudah dilakukan di artikel CentOS Desktop dan CentOS Development Workstation.

pecl install oci8
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading oci8-1.4.7.tgz ...
Starting to download oci8-1.4.7.tgz (168,584 bytes)
....done: 168,584 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
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/11.2/client64/lib
building in /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7
running: /var/tmp/oci8/configure --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib
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 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 ISO C89... 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-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-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 Database OCI8 support... yes, shared
checking PHP version... 5.3.3, 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 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.2/client64/lib
checking Oracle Instant Client SDK header directory... /usr/include/oracle/11.2/client64
checking Oracle Instant Client library version compatibility... 11.1
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1966080
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc 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 ./config.status
config.status: creating config.h
config.status: executing libtool commands
running: make
/bin/sh /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8.c -o oci8.lo
libtool: compile:  cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64 -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8.c  -fPIC -DPIC -o .libs/oci8.o
/bin/sh /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_lob.c -o oci8_lob.lo
libtool: compile:  cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64 -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-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_statement.c -o oci8_statement.lo
libtool: compile:  cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64 -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-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_collection.c -o oci8_collection.lo
libtool: compile:  cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64 -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-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=compile cc  -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64  -DHAVE_CONFIG_H  -g -O2   -c /var/tmp/oci8/oci8_interface.c -o oci8_interface.lo
libtool: compile:  cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64 -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-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=link cc -DPHP_ATOM_INC -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/include -I/var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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/client64  -DHAVE_CONFIG_H  -g -O2   -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/modules  oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/usr/lib/oracle/11.2/client64/lib -L/usr/lib/oracle/11.2/client64/lib -lclntsh
libtool: link: 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/client64/lib -lclntsh  -Wl,-rpath -Wl,/usr/lib/oracle/11.2/client64/lib   -Wl,-soname -Wl,oci8.so -o .libs/oci8.so
libtool: link: ( cd ".libs" && rm -f "oci8.la" && ln -s "../oci8.la" "oci8.la" )
/bin/sh /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/libtool --mode=install cp ./oci8.la /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/modules
libtool: install: cp ./.libs/oci8.so /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/modules/oci8.so
libtool: install: cp ./.libs/oci8.lai /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/modules/oci8.la
libtool: finish: PATH="/usr/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/sbin" ldconfig -n /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /var/tmp/pear-build-jackyhtgHPX8r9/oci8-1.4.7/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-jackyhtgHPX8r9/install-oci8-1.4.7" install
Installing shared extensions:     /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7/usr/lib64/php/modules/
running: find "/var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7" | xargs ls -dils
795162   4 drwxr-xr-x 3 root root   4096 May  8 10:52 /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7
795184   4 drwxr-xr-x 3 root root   4096 May  8 10:52 /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7/usr
795185   4 drwxr-xr-x 3 root root   4096 May  8 10:52 /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7/usr/lib64
795186   4 drwxr-xr-x 3 root root   4096 May  8 10:52 /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7/usr/lib64/php
795187   4 drwxr-xr-x 2 root root   4096 May  8 10:52 /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7/usr/lib64/php/modules
795181 496 -rwxr-xr-x 1 root root 505331 May  8 10:52 /var/tmp/pear-build-jackyhtgHPX8r9/install-oci8-1.4.7/usr/lib64/php/modules/oci8.so

Build process completed successfully
Installing '/usr/lib64/php/modules/oci8.so'
install ok: channel://pecl.php.net/oci8-1.4.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini

Pada proses di atas, saat muncul pertanyaan : 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] :
saya jawab dengan menuliskan : instantclient,/usr/lib/oracle/11.2/client64/lib

Menambahkan extension OCI8 di php.ini

Pada baris terakhir proses di atas, meminta kita untuk menambahkan "extension=oci8.so" di file php.ini, namun saat saya lihat contoh-contoh penambahan php extension yang sudah ada (eksisting), ternyata tidak langsung ditambahkan di file php.ini, melainkan diletakkan di folder /etc/php.d. Di folder tersebut sudah terdapat file gd.ini, mysql.ini, pdo.ini dll yang hanya berisi satu baris menambahkan extension. Saya ikuti untuk membuat file /etc/php.d/oci8.so yang berisi satu baris perintah menambahkan extension oci8.

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

Restart HTTPD

Agar extension OCI8 bisa diload, httpd perlu di-restart.

/etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
	                                                           [  OK  ]

Lihat Informasi Konfigurasi di Php Info

Setelah itu buat file info.php yang berisi :

<?php
    date_default_timezone_set("Asia/Jakarta");
    phpinfo();
?>

Buka melalui browser, tampak file /ect/php.d/oci8.ini sudah diload, namun tidak ada informasi konfigurasi oci8. Berarti terjadi error saat load oci8.so, saya coba lihat log di /var/log/httpd/error_log ternyata ada error berikut :

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/oci8.so' - libclntsh.so.11.1: cannot enable executable stack as shared object requires: Permission denied in Unknown on line 0

Masalahnya permission denied, kemungkinan setingan file chmod perlu diubah menjadi 775 atau bisa juga karena selinux. Saya tidak paham pemanfaatan selinux, jadi solusi yang paling gampang, saya coba dulu selinux dimatikan. gedit /etc/selinux/config

Saya ubah baris SELINUX=enforcing menjadi SELINUX=disabled

httpd saya restart lagi melalui perintah /etc/init.d/httpd restart kemudian melihat log di /var/log/httpd/error_log ternyata tidak ada error. Saya coba refresh phpinfo, well informasi konfigurasi oci8 berhasil ditampilkan.

Sampai di sini, oci8 sudah berhasil diinstal. Anda bisa melanjutkan dengan membuat file PHP sederhana untuk koneksi ke database oracle.

follow article


 

Leave Comment

<i>, <u>, <b> and <a>

Captcha


Reload image