PHP4.3.0 に関するインストールメモ(2003/02/06)
PHP 4.2.x は、セキュリティホールが多数存在します。!!。
HTML文の記述中に、データベースアクセス処理及び Perl 並の文字列処理/if/switch等をサポートした非常に高度なソフトウエアです。しかも、HTML文の中に記述する事ができるため、C言語で作成するときの様にデータベースアクセスライブライを作成したり、各種ライブラリを作成したりとする面倒な手続きがなく、非常に簡単にプログラムを作成することができます。
本家 : 日本PHPユーザ会 [PHP国際版化に関して]
参考 : PHP4で作るWeb-DBシステム
参考 : Apache + PHP4でOracle
参考 : PHP4.0.6+Oracle8iのインストール(DSO版)
参考 : PHP4徹底攻略改訂版のPDF
色々とデータベースをくっ付けました(Oracle8i + PostgreSQL + MySQL)と、Apache ・・・・。
無いと煩く言われますので、下記のソフトは事前に入れておきましょう (^o^)丿 当然最低限 gcc は、いれますよ。ここら辺は、Linuxだと標準で入っているので便利ですよね・・・。(Oracle8i も入れておいてね)
Oracle8i : http://www.gnu.org/software/gcc/gcc.html
gcc : http://www.gnu.org/software/gcc/gcc.html
bison : http://www.gnu.org/software/bison/bison.html
flex : http://www.gnu.org/software/flex/flex.html
patch : http://www.gnu.org/software/patch/patch.html
libtool : http://www.gnu.org/software/libtool
コマンドライン版の PHP を作成するためには、PHP の configure 時に、「--with-apxs, --with-apache」のオプションをつけないと作成できます。すると下記にディレクトリに php 他を含む一連のプログラム/ヘッダが格納されます。
/usr/local/bin/php
/usr/local/lib/php
/usr/local/include/php
1.最新版 PHP4.3.0 を設定します。
% cd /opt/local/src
% wget "http://www.php.net/do_download.php?download_file=php-4.3.0.tar.gz"
% tar zxf php-4.3.0.tar.gz
% cd php-4.3.0
% env CFLAGS=-O3 ./configure \
--with-oracle=/opt/oracle/product/8.1.7 \
--with-oci8=/opt/oracle/product/8.1.7 \
--with-apxs=/opt/local/apache/bin/apxs \
--enable-sigchild \
--enable-mbstring \ ← マルチバイト
--enable-mbstr-enc-trans \ ← HTTP入力の自動エンコーディング
--enable-mbregex \ ← 日本語正規表現
--with-pgsql=/opt/local/pgsql \
--with-mysql=/opt/sfw/mysql
% make
% su
# make install★) MySQL を使うオプションを指定すると、下記の様なエラーが発生します。とりあえずエラーを出さない方法は、強制的にリンクを行っちゃうのも手なんで・・・・・安易? (ーー゛)
ld: fatal: file /opt/sfw/mysql/lib/mysql/.libs/libmysqlclient.so: open failed: No such file or directory
ld: fatal: File processing errors. No output written to .libs/libphp4.so
make[1]: *** [libphp4.la] Error 1
make[1]: Leaving directory `/opt/local/src/php-4.3.0'
make: *** [all-recursive] Error 1
# ln -s /opt/sfw/mysql/lib/mysql /opt/sfw/mysql/lib/mysql/.libs ← 強制リンクぅ2.php.ini ファイルをコピーし内容を編集する
# cp /opt/local/src/php-4.3.0/php.ini-dist /usr/local/lib/php.ini
# vi /usr/local/lib/php.ini
output_buffering = Off
→ output_buffering = On
output_handler =
→ output_handler = mb_output_handler
[mbstring]
;mbstring.internal_encoding = EUC-JP
;mbstring.http_input = auto
;mbstring.http_output = SJIS
;mbstring.detect_order = auto
;mbstring.substitute_character = none;
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = SJIS
mbstring.detect_order = auto
mbstring.substitute_character = none
設定値 : http://jp.php.net/manual/ja/ref.mbstring.php
3.Apache の再コンパイルを行います。
% cd /opt/local/src/apache_1.3.26
% env SSL_BASE=/opt/local/src/openssl-0.9.6c env CFLAGS=-O3 \
./configure --prefix=/opt/local/apache \
--enable-module=most --enable-shared=max \
--enable-module=ssl
% make
% su
# make install4.Apache の httpd.conf 内容を設定する。
# vi /opt/local/apache/conf/httpd.conf
LoadModule php4_module libexec/libphp4.so
AddModule mod_php4.c
<IfModule mod_php4.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>5.Apache の 起動停止スクリプトに Oracle8i の環境変数を定義します。ついでに再起動を行います。
# vi /etc/init.d/apache
# /etc/init.d/apache restart6.サンプルソースを実行してみます。(Oracle8i との接続テスト)
<b>●Oracleとの接続テスト</b>
<hr>
<?php
// Oracleとの接続
$conn = OCILogon("scott", "tiger");
// SQL文のparse
$stmt = OCIParse($conn,"select * from emp ");
// SQL文の実行
OCIExecute($stmt);
$ncols = OCINumCols($stmt);
echo "<TABLE BORDER='1'>";
echo "<TR>";
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
echo "<TH>" . $column_name . "</TH>";
}
echo "</TR>";
// データのFetch
while(OCIFetch($stmt)) {
echo "<TR>";
for ( $i = 1; $i <= $ncols; $i++ ) {
$column_name = OCIColumnName($stmt,$i);
// データの表示
echo "<TD>" . OCIResult($stmt, $column_name) . "</TD>";
}
echo "</TR>";
}
echo "</TABLE>";
// リソースの解放
OCIFreeStatement($stmt);
// Oracleから切断
OCILogoff($conn);
?>