Submitted by sasaki on 月曜, 2008-09-08 17:33.
イントラネットの引っ越しで、PHPを新しいSolarisにインストールする。
■古いサーバで、PHPのバージョンと、インストールオプションを調べる
サーバーAにインストールされているPHP
$ php -i
バージョン: 4.4.2
コンフィグ: './configure' '--with-mysql' '--with-apxs=/usr/apache/bin/apxs' '--enable-mbstring' '--with-gd' '--with-zlib'
設定ファイル: /usr/local/lib/php.ini
MySQLのAPI: 3.23.49
MySQLのソケット: /tmp/mysql.sock
というようなことが分かる。
サーバーBにインストールされているPHP
$ php -i
PHP Version => 5.2.0
System => SunOS bdj-intra2.bdjapan.com 5.10 Generic_118833-24 sun4u
Build Date => Jan 22 2007 16:08:54
Configure Command => './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '
--enable-zend-multibyte' '--enable-mbstring=shared' '--with-oci8=shared' '--enab
le-sigchild'
■前準備をしておく
apxsの場所をfindコマンドで探した。
/usr/apache/bin/apxs
/usr/apache2/bin/apxs
■新しいサーバで、PHPをコンパイルしてインストールする
サーバーAの代わりの新しいサーバCにインストール。
せっかくの機会なので、PHP5を用意した。上手く動かないものがあればPHP4にすればいいや...と。
$ cd /usr/local/src
$ tar zxvf php-5.2.6.tar.gz
$ cd php-5.2.6
$ ./configure --help (オプションを確認しておく)
$ ./configure --with-mysql=/usr/sfw --with-apxs=/usr/apache/bin/apxs
--enable-mbstring --with-gd --with-zlib
$ make
(最後にこのメッセージが表示されれば成功。)
Build complete.
Don't forget to run 'make test'.
$ make test
--with-mysqlで、パスを指定しないとこのようなエラーが表示される。
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
/usr/sfw/mysql/の下にはlibとincludeが無いので、一つ上のディレクトリ/usr/sfw/を指定した。
rootユーザでインストールを実行する。 メッセージをメモしておくとよい。
# make install
Installing PHP SAPI module: apache
[activating module `php5' in /etc/apache/httpd.conf]
cp libs/libphp5.so /usr/apache/libexec/libphp5.so
chmod 755 /usr/apache/libexec/libphp5.so
cp /etc/apache/httpd.conf /etc/apache/httpd.conf.bak
cp /etc/apache/httpd.conf.new /etc/apache/httpd.conf
rm /etc/apache/httpd.conf.new
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Archive_Tar - installed: 1.3.2
[PEAR] Structures_Graph- installed: 1.0.2
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
[PEAR] PEAR - installed: 1.7.1
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/include/php/ext/pdo/
Apacheを停止、起動させて、PHPを有効にする。
サーバーBの代わりの新しいサーバーDにインストールする。
Oracle実行ユーザーで./configureを実行したときのメモ。(実際には一行で実行する)
./configure --with-mysql=/usr/sfw
--with-apxs2=/usr/apache2/bin/apxs
--enable-mbstring
--enable-zend-multibyte
--with-gd
--with-zlib
--with-oci8=shared,/u01/app/oracle/product/10.2.0
--enable-sigchild
オプションの詳細。
apache2の場合は、--with-apxs2を指定する。
shared指定: shared extension としてコンパイルされる。
./configure --help | less で調べた情報。Oracleインスタントクライアントの場合の参考に。
--with-oci8[=DIR] Include Oracle (OCI8) support. DIR defaults to $ORACLE_HOME.
Use --with-oci8=instantclient,/path/to/oic/lib
for an Oracle Instant Client installation
--enable-sigchild Enable PHP's own SIGCHLD handler
ちなみに --with-oracle[=DIR] は、oci7用らしい。
Oracle実行ユーザで./configureしなかった場合、$ORACLE_HOME以下へのアクセス権限が無くてこのようなエラーが発生する。
checking OCI8 libraries dir... configure: error: Oracle (OCI8) required libraries not found
make test したときに、You may have found a problem in PHP. というメッセージが最後に出たが、make installのメッセージを見たところ、まあ大丈夫かな...。
# make install
Installing PHP SAPI module: apache2handler
/var/apache2/build/instdso.sh SH_LIBTOOL=
'/var/apache2/build/libtool' libphp5.la /usr/apache2/libexec
/var/apache2/build/libtool --mode=install cp libphp5.la /usr/apache2/libexec/
cp .libs/libphp5.so /usr/apache2/libexec/libphp5.so
chmod +x /usr/apache2/libexec/libphp5.so
cp .libs/libphp5.lai /usr/apache2/libexec/libphp5.la
libtool: install: warning: remember to run `libtool --finish /usr/local/src/php-5.2.6/libs'
chmod 755 /usr/apache2/libexec/libphp5.so
[activating module `php5' in /etc/apache2/httpd.conf]
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Archive_Tar - installed: 1.3.2
[PEAR] Structures_Graph- installed: 1.0.2
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
[PEAR] PEAR - installed: 1.7.1
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/include/php/ext/pdo/
■php.iniを用意する
インストールが終わったら引き続き、php.iniを設置する。
php.iniの設置場所を確認する。
# /usr/local/bin/php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
php.ini-dist または php.ini-recommendedを/usr/local/libにphp.iniとファイル名を変更してコピーする。(2つのファイルの違いはdiffコマンドで確認)
# cp php.ini-dist /usr/local/lib/php.ini
以前のサーバで利用していた/usr/local/lib/php.iniの内容をチェックして、必要であればこのサーバのphp.iniの内容を変更する。
php.iniの設置を確認する。
# /usr/local/bin/php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
■httpd.confを設定する
追加されたPHPモジュールを確認する。
LoadModule php4_module libexec/libphp4.so
AddModule mod_php4.c
*.phpファイルが、PHPを実行できるように設定を追加する。
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
設定後、apacheを再起動する。