PHPをアップグレードする。 - 5.1.6から5.2系へ

正直、5.3へ…とも思ったけど、とりあえずは5.2系にしておくことにした。

元々復活させた古いVMwareで動かそうとしたのが間違いだったか?
要するにSQLiteが動かない。
正確にはSQLiteのバージョン2系なんだけどね。

php -i

とか

phpinfo();

で確認すると、「--without-sqlite」ってなってるんだよね。


まずはphp5.1.6→PHP5.2環境へバージョンアップというページを参考に、リポジトリを追加しつつ5.1.6から5.2.11へアップさせた。


…が、yumで入れるってことは、configureのオプションは同じなワケで、phpizeも入らなければ、「--without-sqlite」のまま。


ソースから入れることにしました。
yumで入れたPHPをソースからコンパイルしたPHPと入れ替える - blog.katsuma.tv
このページを参考にさせてもらいます。


削除前のphpinfo()からconfigureオプションをコピーして、「--without-sqlite」だけを「--with-sqlite」に変更してconfig!

./configure --host=i686-redhat-linux-gnu --build=i686-redhat-linux-gnu --target=i386-redhat-linux --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-libdir=lib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --disable-debug --with-pic --disable-rpath --without-pear --with-bz2 --with-curl --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-pcre-regex=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-wddx --with-kerberos --enable-ucd-snmp-hack --enable-shmop --enable-calendar --without-mime-magic --with-sqlite --with-libxml-dir=/usr --enable-xml --with-system-tzdata --with-apxs2=/usr/sbin/apxs --without-mysql --without-gd --disable-dom --disable-dba --without-unixODBC --disable-pdo --disable-xmlreader --disable-xmlwriter --disable-json --without-pspell


これが果てしない旅の始まりだと、誰が予想しただろう。

./configure: line 6461: /usr/sbin/apxs: No such file or directory
configure: error: Aborting

あ、あれ?
一応は同じオプションのはずなんだけどなぁ。
でもよく考えれば、yumで入れるってことは、自動でコンパイルしてくれるってこととは違うんだよな、多分。よく判らんけど。


まぁ、いいか。


面倒なんでyumで探す。

# yum search apxs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: ftp.iij.ad.jp
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 =============================================================================== Matched: apxs ================================================================================
httpd-devel.i386 : Development interfaces for the Apache HTTP server

ってことは、httpd-develを入れればいいのかな?

# yum install httpd-devel

で、再度config実行。

configure: error: xml2-config not found. Please check your libxml2 installation.

あれ?
yum list」と「yum info」でlibxml2を探すけど、インストール済み。
configオプションは「--with-libxml-dir=/usr」となっている。
libxml*をfindで検索すると

/usr/lib/libxml2.so.2.6.26
/usr/lib/libxml2.so.2

このふたつがそれっぽいな。
「--with-libxml-dir=/usr/lib」に変えてみるか。

configure: error: xml2-config not found. Please check your libxml2 installation.

あ、あれ!?

libxml2系のモジュールのインストールが足りないみたいのなので、libxml2-delvelを取得してインストール。

# wget http://xmlsoft.org/sources/libxml2-devel-2.6.15-1.i386.rpm
# rpm -ivh libxml2-devel-2.6.15-1.i386.rpm

もう一度、configureしてみる。

# ./configure --with-apxs=/usr/local/apache/bin/apxs --enable-mbstring --enable-mbregex

「Build complete.」
とでたのでOK。
あとは、makeとmake installを行う。

PHP バージョンアップ インストール - Shoulder.jp

あ、パスが違うとかじゃないのか。

# yum install libxml2-devel

とりあえず「--with-libxml-dir=/usr」に戻して、configしてみる。

checking for xml2-config path... /usr//bin/xml2-config

通った!


ところが…

configure: error: Cannot find OpenSSL's <evp.h>

おい!
PHP 5.3.0インストールログ
このブログを見ると、openssl-develを導入後にこのエラーが出てるようで、この人は自前でopensslを入れなおしている。
で、自分の環境はどうかというと、「updates」になっている。
どうしようかと思ったけど、

# yum install openssl-devel

を実行してみたら、インストールが開始された。


ってことで、再度configを走らせる。

checking for OpenSSL support... yes

さて、次はどこでつまずくよ?

configure: error: Could not find pcre.h in /usr

もうダメ…
やめようかな?

# yum list pcre*

pcre-develが「Available Packages」になってる。

# yum install pcre-devel -y

インストール完了!


あれだな、要するにエラーが出た場合は、モジュールそのものではなく「-devel」が付くやつを入れろってことなんだ。


再びconfigを開始…

configure: error: Please reinstall the BZip2 distribution

で、予想通りbzip2-develがない(Available Packages)らしい。

# yum install bzip2-devel -y


もしかして

# yum install *devel -y

でインストールした方が早いとか?

configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/

はいはい…

# yum search libcurl

で確認して、curl-develを入れる。

# yum install curl-devel -y


一体いつ終わるんだ?

configure: error: Unable to locate gmp.h

ガックシ。

# yum search gmp
# yum list gmp*

で確認して、

# yum install gmp-devel -y

で、config再開。


まだlibjpegのエラーが出てこないが、大丈夫かなぁ?


正直、このトライ&エラーは辛い。
configチェックみたいなのってないのかね。
ぜーんぶチェックして、エラーを列挙してくれるような、さ。

Generating files

キタ!

Thank you for using PHP.

Notice: Following unknown configure options were used:

--with-system-tzdata

Check './configure --help' for available options

あ、変なオプションが混ざってたらしい。


やっとここまで来た。

# make test

やっぱり確認してからでないと、心配でしょ?


…長い。
PuTTYでログ取りながらだからかな。


終わった!と思ったら、なんかエラーが出たっぽい。

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
easter_date() [ext/calendar/tests/easter_date.phpt]
unixtojd() [ext/calendar/tests/unixtojd.phpt]
Test DateTime::modify() function : usage variation - Passing unexpected values to first argument $modify. [ext/date/tests/DateTime_modify_variation1.phpt]
Test date_modify() function : usage variation - Passing unexpected values to second argument $format. [ext/date/tests/date_modify_variation2.phpt]
Test date_sunrise() function : usage variation - Passing unexpected values to fifth argument zenith [ext/date/tests/date_sunrise_variation5.phpt]
Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36) [ext/gmp/tests/bug50283.phpt]
Bug #41638 (pcre 7.0 regression) [ext/pcre/tests/bug41638.phpt]
Bug #42298 (pcre gives bogus results with /u) [ext/pcre/tests/bug42298.phpt]
SPL: DirectoryIterator test getGroup [ext/spl/tests/DirectoryIterator_getGroup_basic.phpt]
SPL: Spl Directory Iterator test getOwner [ext/spl/tests/DirectoryIterator_getOwner_basic.phpt]
=====================================================================

easter_date()*1もunixtojd()*2も使ったことないし、問題ないっしょ(自信ないけど)。
pcreに問題があるのかなぁ?

# make

Build complete.
Don't forget to run 'make test'.

忘れてないよ。


いよいよ、本番です。

# make install
Installing PHP SAPI module:       apache2handler
/usr/lib/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib/apr-1/build/libtool' libphp5.la /usr/lib/httpd/modules
/usr/lib/apr-1/build/libtool --mode=install cp libphp5.la /usr/lib/httpd/modules/
cp .libs/libphp5.so /usr/lib/httpd/modules/libphp5.so
cp .libs/libphp5.lai /usr/lib/httpd/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /root/src/php-5.2.13/libs'
chmod 755 /usr/lib/httpd/modules/libphp5.so
[activating module `php5' in /etc/httpd/conf/httpd.conf]
Installing PHP CLI binary:        /usr/bin/
Installing PHP CLI man page:      /usr/share/man/man1/
Installing build environment:     /usr/lib/build/
Installing header files:          /usr/include/php/
Installing helper programs:       /usr/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/share/man/man1/
  page: phpize.1
  page: php-config.1

終わった。


とりあえずhttpd再起動!

# apachectl restart
[Wed Apr 21 15:04:22 2010] [warn] module php5_module is already loaded, skipping

ま、まさか…!


httpd.confにダブって記述されてるワケでもないのに…


/etc/httpd/conf.d/php.conf か。

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule php5_module modules/libphp5.so

#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps

httpd.conf側を削除して、再起動。


警告も出ず、再起動が完了しました。

phpinfo();

でバージョンが変わっていることも確認できたし、SQLiteの項目も確認できた。
テスト用のファイルもアップして、動作も確認できた。


長かった…

*1:指定した年における復活祭の真夜中のUnix時を得る

*2:Unix タイムスタンプをユリウス歴に変換する