メニュー
プロフィール
最近の記事
カテゴリ分類
記事一覧
FOR ENGINEERS
注目! テレビや雑誌でも紹介されているペン型ICレコーダー

RedHat Enterprise Linux 5.2 で動かしている Oracle11gデータベースに対し、
PHPからOCI8でアクセスしたい。

●オラクルのバージョンは 11.1.0.6.0
●PHPのバージョンは 5.1.6-20

以前に作業した RHEL5 + Oracle10gR2 環境で PHPを使えるようにする作業に習って作業したのだが、うまく行かなかった。
【RHEL5】PHP から Oracle DB にアクセスする
この方法はPHPをソースコードから再コンパイルするので、
ついでに最新のPHPバージョンにアップデートできるというメリットもあるのだが、
セットアップできないのでは話にならない。

そのため peclを使う方法で作業する事にした。

この場合、既にPHPがセットアップされていないといけない。
従ってディストリビューションに含まれるPHPをセットアップしておく。

以下、rootにて。
# cd /media/..   # DVDドライブに移動
# cd Server
# rpm -ivh php-*
以上でPHPをセットアップ。

以下、OCI8をセットアップする。
ソースコードからコンパイルする手順に比べると、はるかに簡単です。
OCI8のセットアップでは、Instant Clientを使う方法もあるが、
このサーバーには既に Oracle11g (11.1.0.6.0)がセットアップされているので、これを使いたい。
そのため、以下のように作業する。
# pecl install oci8
downloading oci8-1.3.4.tgz ...
Starting to download oci8-1.3.4.tgz (134,240 bytes)
.....done: 134,240 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "ja_JP.UTF-8",
LANG = "ja_JP.SJIS"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "ja_JP.UTF-8",
LANG = "ja_JP.SJIS"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
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] : /u01/app/oracle/product/11.1.0/db_1
building in /var/tmp/pear-build-root/oci8-1.3.4
running: /tmp/tmppRhDk7/oci8-1.3.4/configure --with-oci8=/u01/app/oracle/product/11.1.0/db_1
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... 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
checking for PHP extension directory... /usr/lib/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 Oracle Install Directory... /u01/app/oracle/product/11.1.0/db_1
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... 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++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for g77... g77
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether g77 accepts -g... yes
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
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ 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
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 g77 option to produce PIC... -fPIC
checking if g77 PIC flag -fPIC works... yes
checking if g77 static flag -static works... yes
checking if g77 supports -c -o file.o... yes
checking whether the g77 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.3.4/libtool --mode=compile gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8.c -o oci8.lo
mkdir .libs
gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8.c -fPIC -DPIC -o .libs/oci8.o
/bin/sh /var/tmp/pear-build-root/oci8-1.3.4/libtool --mode=compile gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_lob.c -o oci8_lob.lo
gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_lob.c -fPIC -DPIC -o .libs/oci8_lob.o
/bin/sh /var/tmp/pear-build-root/oci8-1.3.4/libtool --mode=compile gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_statement.c -o oci8_statement.lo
gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_statement.c -fPIC -DPIC -o .libs/oci8_statement.o
/bin/sh /var/tmp/pear-build-root/oci8-1.3.4/libtool --mode=compile gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_collection.c -o oci8_collection.lo
gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_collection.c -fPIC -DPIC -o .libs/oci8_collection.o
/bin/sh /var/tmp/pear-build-root/oci8-1.3.4/libtool --mode=compile gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_interface.c -o oci8_interface.lo
gcc -I. -I/tmp/tmppRhDk7/oci8-1.3.4 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -c /tmp/tmppRhDk7/oci8-1.3.4/oci8_interface.c -fPIC -DPIC -o .libs/oci8_interface.o
/bin/sh /var/tmp/pear-build-root/oci8-1.3.4/libtool --mode=link gcc -DPHP_ATOM_INC -I/var/tmp/pear-build-root/oci8-1.3.4/include -I/var/tmp/pear-build-root/oci8-1.3.4/main -I/tmp/tmppRhDk7/oci8-1.3.4 -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/u01/app/oracle/product/11.1.0/db_1/rdbms/public -I/u01/app/oracle/product/11.1.0/db_1/rdbms/demo -DHAVE_CONFIG_H -g -O2 -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root/oci8-1.3.4/modules oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/u01/app/oracle/product/11.1.0/db_1/lib -L/u01/app/oracle/product/11.1.0/db_1/lib -lclntsh
gcc -shared .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o -L/u01/app/oracle/product/11.1.0/db_1/lib -lclntsh -Wl,-rpath -Wl,/u01/app/oracle/product/11.1.0/db_1/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.3.4/libtool --mode=install cp ./oci8.la /var/tmp/pear-build-root/oci8-1.3.4/modules
cp ./.libs/oci8.so /var/tmp/pear-build-root/oci8-1.3.4/modules/oci8.so
cp ./.libs/oci8.lai /var/tmp/pear-build-root/oci8-1.3.4/modules/oci8.la
PATH="$PATH:/sbin" ldconfig -n /var/tmp/pear-build-root/oci8-1.3.4/modules
----------------------------------------------------------------------
Libraries have been installed in:
/var/tmp/pear-build-root/oci8-1.3.4/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).

running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-oci8-1.3.4" install
Installing shared extensions: /var/tmp/pear-build-root/install-oci8-1.3.4/usr/lib/php/modules/
running: find "/var/tmp/pear-build-root/install-oci8-1.3.4" -ls
6881724 4 drwxr-xr-x 3 root root 4096 Jan 28 15:11 /var/tmp/pear-build-root/install-oci8-1.3.4
6881753 4 drwxr-xr-x 3 root root 4096 Jan 28 15:11 /var/tmp/pear-build-root/install-oci8-1.3.4/usr
6881754 4 drwxr-xr-x 3 root root 4096 Jan 28 15:11 /var/tmp/pear-build-root/install-oci8-1.3.4/usr/lib
6881755 4 drwxr-xr-x 3 root root 4096 Jan 28 15:11 /var/tmp/pear-build-root/install-oci8-1.3.4/usr/lib/php
6881756 4 drwxr-xr-x 2 root root 4096 Jan 28 15:11 /var/tmp/pear-build-root/install-oci8-1.3.4/usr/lib/php/modules
6881752 384 -rwxr-xr-x 1 root root 388194 Jan 28 15:11 /var/tmp/pear-build-root/install-oci8-1.3.4/usr/lib/php/modules/oci8.so

Build process completed successfully
Installing '/var/tmp/pear-build-root/install-oci8-1.3.4//usr/lib/php/modules/oci8.so'
install ok: channel://pecl.php.net/oci8-1.3.4
You should add "extension=oci8.so" to php.ini
以上にて oci8.so が正常にセットアップされました。
引き続き PHPにoci8の設定を加え、apacheを再起動します。
# echo "extension=oci8.so" > /etc/php.d/oci8.ini
# service httpd restart
これで phpinfo ()を呼び出して「oci8」がロードされているかどうか確認します。

また apache の実行ユーザーの環境変数に ORACLE_HOME が設定する必要があるので、以下の設定を登録しておく。
#vi /etc/syscofig/httpd

--- begin httpd
...
#↓最後に以下を追加
export NLS_LANG=Japanese_Japan.JA16SJISTILDE
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export ORACLE_SID=サービス名

--- end httpd

# service httpd restart



参考)
【PHP】Instant Client+peclでoci8(oracle)関数を使えるようにする

| ネット関連::PHP | 05:45 PM | comments (x) | trackback (x) |
PAGE TOP ↑