[開発環境] PHP5.2 と PHP5.3 の共存

Posted on 2010/12/18 | Category: PHP, Server | タグ:

Fedora14 には標準で PHP5.3系が入ってる。
これはうれしいが、 PHP5.2系を使いたいときもある。

両方入れて切り替えができたらいいよね。
で↓これ
http://tech.kayac.com/archive/php53_and_php52.html

Macでのやり方なのでそのままできないけど。

PHP のインストール

configure オプションは以下の通り。
いくつかエラーを乗り越える必要があるよ。
対処法は後述。

結果的 configure オプション

./configure \
--prefix=/php-5.2.15 \
--mandir=/php-5.2.15/share/man \
--infodir=/php-5.2.15/share/info \
--with-config-file-path=/php-5.2.15/etc/php5 \
--with-config-file-scan-dir=/php-5.2.15/var/db/php5 \
--enable-bcmath \
--enable-ctype \
--enable-dom \
--enable-filter \
--enable-hash \
--enable-json \
--enable-libxml \
--enable-mbstring \
--enable-pdo \
--enable-session \
--enable-simplexml \
--enable-tokenizer \
--enable-xml \
--enable-xmlreader \
--enable-xmlwriter \
--with-bz2=/usr/include \
--with-gd=/usr/include \
--with-mcrypt=/usr/include \
--with-mhash=/usr/include \
--with-mysql \
--with-pcre-regex=/usr/local \
--with-readline=/usr/include \
--with-libxml-dir=/usr/include \
--with-zlib=/usr/local \
--without-pear \
--disable-cgi \
--with-ldap=/usr \
--with-apxs2=/usr/sbin/apxs

以下、立ちふさがったエラーたち。
Fedora をセットアップしたばかりのサラの状態からスタートね。

gcc がないよ!

エラーメッセージ

configure: error: no acceptable C compiler found in $PATH

対処法
gcc をインストール。依存もまとめて。

# yum install gcc
/usr/sbin/apxs が見つからない!

エラーメッセージ

Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/sbin/apxs follows:
./configure: line 6731: /usr/sbin/apxs: No such file or directory
configure: error: Aborting

対処法
httpd-devel をインストール。

# yum install httpd-devel
xml2-config が見つからない!

エラーメッセージ

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

対処法
libxml2 をインストール。

# yum install libxml2

しかしここでまたもや問題発生。
yum でインストールしようとすると「最新版です!」と怒られる。
なのでファイルからインストールしよう
本家サイトに行き、ftp://xmlsoft.org/libxml2/ で最新版のURLを確認。
2010/12/17 現在の最新版は 2.7.8。

# wget ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
# tar zxvf libxml2-2.7.8.tar.gz
# cd libxml2-2.7.8
# ./configure
# make
# make install
pcre.h が見つからない!

エラーメッセージ

error: Could not find pcre.h in /usr

対処法
pcre をインストール。
下記サイトで最新版のURLを確認。
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
2010/12/17 現在の最新版は 8.11。

# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.11.tar.gz
# tar zxvf pcre-8.11.tar.gz
# cd pcre-8.11
# ./configure
# make
# make install

インストール場所をかえたので configure オプションに反映。

--with-pcre-regex=/usr/local
g++ コマンドが見つからない!

エラーメッセージ

error: Could not find pcre.h in /usr

対処法
gcc-c++ をインストール。

# yum install gcc-c++
libz がないよ!

エラーメッセージ

configure: error: cannot find libz

対処法
本家サイトで最新版のURLを確認。
2010/12/17 現在の最新版は 1.2.5。

# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.5.tar.gz?download
# tar zxvf zlib-1.2.5.tar.gz
# cd zlib-1.2.5
# ./configure
# make
# make install
bzip2 がないよ!

エラーメッセージ

configure: error: Please reinstall the BZip2 distribution =>

対処法
yum からまとめてインストール。

# yum install bzip2\*
gd.h が見つからない!

エラーメッセージ

configure: error: Unable to find gd.h anywhere under

対処法
必要なライブラリをすべてインストール。

# yum -install gd gd-devel freetype freetype2 libpng libmng\* libtiff\* libjpeg\* libc-client\* giflib\*

続いて libiconv をインストール。
下記サイトで最新版のURLを確認。
http://ftp.gnu.org/pub/gnu/libiconv/
2010/12/17 現在の最新版は 1.13.1。

# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
# tar zxvf libiconv-1.13.1.tar.gz
# cd libiconv-1.13.1
# ./configure
# make
# make install

LDFLAGSをセット

export LDFLAGS=-liconv

インストール場所をかえたので configure オプションに反映。

--with-pcre-regex=/usr/local
libgd が見つからない!

エラーメッセージ

configure: error: Unable to find libgd.(a|so) anywhere under /usr/include

対処法
libgd をインストール。
下記サイトで最新版のURLを確認。
http://www.libgd.org/Downloads
2010/12/17 現在の最新版は 2.0.35。

# wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
# tar zxvf gd-2.0.35.tar.gz
# cd gd-2.0.35

それでもエラーがでます。。。
どうやらファイル名が違うらしい。

# ln -s /usr/lib64/libgd.so.2.0.0 /usr/include/libgd.so
mcrypt.hがない!

エラーメッセージ

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

対処法
libmcrypt-devel をインストール。
その前に mcrypt は libmhash に依存しているので先にこちらをインストール。

# yum install libmhash-devel

続いて libmcrypt-devel をインストール。

# yum install libmcrypt-devel

これで OK(のはず)!

ようやく PHP のインストール

make の前に↓このファイル名を変更。

/usr/local/httpd/modules/libphp5.so

↓こんな感じ

# cd /usr/local/httpd/modules
# mv libphp5.so libphp53.so

そして PHP インストール。

# cd (phpを解凍したディレクトリ)
# make
# make install

libphp5.so が作成されるので、それもわかりやすくリネーム。

# cd /usr/local/httpd/modules
# mv libphp5.so libphp52.so

でけた!

Apache の PHP 関連の設定

インストールおよびファイル名の変更が終わったらあとは Apache の設定で制御。
httpd.conf の

LoadModule php5_module modules/libphp5.so

をコメントアウト。
conf.d にある php.conf で切り替えを行う。
PHP5.3を使う場合は、

LoadModule php5_module modules/libphp53.so

PHP5.2を使う場合は、

LoadModule php5_module modules/libphp52.so

Post to Twitter Post to Facebook Post to FriendFeed Post to LinkedIn

  • http://www.yokada.net/blog/2150 Serverman@VPSのphpを動作確認用に5.2、5.3を切り替えられるようにする » LandEscape Graphics