Oracle+PHP [ メイン ] システム管理者の日...![]()
2007年07月13日
Oracle+PHPこぼれ話
このエントリーのトラックバックURL:
http://www.takumi-server.net/cgi-bin/mt/mt-tb.cgi/33
こんにちは、担当上岡です。
前回お話ししたRHEL4+Apache2+PHP4+Oracle9.2でのインストール時の、ちょっとしたハマりポイントをご紹介します。Oracleに関しては、テクニカルサポートを受けた内容を公開してはならないことになっていますので、その辺りでのおもしろいハマり話は書けないので、悪しからずご了承ください。
さてさて、今回PHP->Oracleへの接続には、最近Oracle 10gで主流の「Oracle Instant Client」ではなく、Oracle 8iから使える「Oracle Database Client」を利用しました。
PHPから利用するには、Oracleのライブラリを取り込む必要があります。RHELを使う場合、教科書的にはSRPMのspecfileでconfigureを書き換えてパッケージをリビルドするのが常道ですが、今回はPHPだけをソースからインストールすることにしました。
PHPのソースディレクトリで、configureのオプションにOracle関連のパスを指定します(sharedライブラリではなく、静的にリンクします)
% ./configure --prefix=/usr/local/php-4.3.9 --with-apxs2=/usr/sbin/apxs \ --with-oracle=/home/oracle/app/oracle/product/9.2 \ --with-oci8=/home/oracle/app/oracle/product/9.2 \ --enable-zend-multibyte \ --enable-memory-limit \ --with-xml \ --with-wddx \ --enable-inline-optimization \ --enable-track-vars \ --enable-magic-quotes \ --with-gettext \ --with-iconv \ --enable-mbstring \ --enable-mbregex \ --enable-versioning \ --with-mysql=/usr \ --enable-sigchild
で、configureがうまくいったら
% make
# make install
ここまでは何の問題もなく完了しました。
しかし、、いざphp.iniを書き換えてApacheを再起動してみると??
httpd [NG] Syntax error on line 190 of /etc/httpd/conf/httpd.conf: Cannot load /usr/lib/httpd/modules/libphp4.so into server: libclntsh.so.9.0: cannot open shared object file: Permission denied
/home/oracle以下は、apacheのユーザーからも参照できるパーミッションになっています。しかし、Permission Deniedとなるわけです。
いきなり答えを言ってしまうと、原因はSELinuxが「enforced」のモードで動いていたからでした(RHEL4では、インストール時にオプションが選べず、勝手にenforcedになってしまう)。httpdやphp,oracleのエラーログ等を見ても異常はなく、/var/log/messagesに
Jul 13 15:46:12 testhost kernel: audit(1184309166.264:899): avc: denied { search } for pid=12018 comm="httpd" name="lib" dev=dm-4 ino=33420 scontext=root:system_r:httpd_t tcontext=user_u:object_r:file_t tclass=dir
ライブラリが読めない旨が延々と書かれています。
SELinux側の設定で、Oracleのライブラリのパスを「アクセス可能な場所」として設定する方法もありますが、今回はテストサーバで、しかも非公開なのでSELinuxそのものを無効にしました。
SELinuxの無効化は、前にも書いたかもしれませんが/etc/sysconfig/selinuxを編集して再起動すればOKです。
無事、Apache+phpがoracle,oci8の関数を使える状態で立ち上がりました。
(#コマンドなどの引用が見にくいので、近々テンプレートを改良します。。。)
日時:2007年07月13日 16:04 | パーマリンク
トラックバック
このエントリーのトラックバックURL:
http://www.takumi-server.net/cgi-bin/mt/mt-tb.cgi/33


コメント (1)
cj:
The trouble with PHP 4.3.9 is that the latest, improved oci8 extension is only compatible with 4.3.10 onwards. For PHP 4 users we always recommend using the latest oci8 extension from PECL because it is _vastly_ improved. However you can make the latest oci8 work with PHP 4.3.9 too with these instructions:
tar -xjf php-4.3.9.tar.bz2
cd php-4.3.9
rm -rf ext/oci8
Download OCI8 from PECL http://pecl.php.net/package/oci8
tar -xzf oci8-1.2.3.tgz
mv oci8-1.2.3 /ext/oci8
Edit ext/oci8/config.m4 and change test and the version in the line:
if test "$oci8_php_version" -le "4003010"; then
to
if test "$oci8_php_version" -lt "4003009"; then
Edit ext/oci8/oci8_collection.c at about line 334 and change
element_double = zend_strtod(number, NULL);
to
element_double = strtod(number, NULL);
and similarly change the line about 334:
element_double = zend_strtod(number, NULL);
to
element_double = strtod(number, NULL);
Run ./buildconf --force
Run your desired "configure" and "make" commands
Test, test, and test.
投稿者:cj | 2007年07月26日 03:02