前提
Linux
環境上での話。方針としては、PHP複数インスタンス環境作成することで実現。
ただし、PHPの各バージョンをソースからインストールしていること。
①/etc/sysconfig/httpdファイルの編集
-
httpd
ファイルのコピーを作成
$ cp /etc/sysconfig/httpd /etc/sysconfig/httpdtest
- コピーファイルの変更
$ vi /etc/sysconfig/httpdtest
変更内容はこんな感じ。
HTTPD=/usr/sbin/httpd.workertest
OPTIONS="-f /etc/httpd/conf/httpdtest.conf"
PIDFILE=/var/run/httpd/httpdtest.pid
- 起動ワーカーをコピー
$ cp /usr/sbin/httpd /usr/sbin/httpd.workertest
②/etc/httpd/conf/http.confファイルの編集
-
httpd.conf
のコピーを作成
$ cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpdtest.conf
- コピーファイルの変更
$ vi /etc/httpd/conf/httpdtest.conf
変更内容はこんな感じ。(適宜変更してください)
- Listen 8888
- その他VirtuslHostなど80を8888にする
- 既存の設定ファイルを参照しないようにする
cp -R /etc/httpd/conf.d /etc/httpd/conftest.d
-
include conftest.d/*.conf
※conftest.d 内のSSLモジュールなど一部の設定ファイルをどこかに移動
※設定ファイル内のログのパス名も既存とは異なる場所にリネーム
※conftest.d/php.conf 内のPHP 設定を書き換える
③/etc/init.d/httpdファイルの編集
-
init.d/httpd
のコピーを作成
$ cp /etc/init.d/httpd /etc/init.d/httpdtest
- コピーファイルの変更
$ vi /etc/init.d/httpdtest
変更内容はこんな感じ。
if [ -f /etc/sysconfig/httpdtest ]; then
. /etc/sysconfig/httpdtest
fi
pidfile=${PIDFILE-/var/run/httpd/httpdtest.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpdtest}
④apache別インスタンス起動
$ /etc/init.d/httpdtest start
起動後はhttp://localhost:8888 でテストする。
※停止後はプロセスゴミが残っていないか確認
$ ps aux | grep /usr/sbin/httpd.workertest
余談
phpenv
を使ってやろうとしたのだが何故か上手くいかなく、上記のやり方を教わった。いろいろ工夫してみるものだな。ただ、phpenvが上手くいかない原因は知りたいから、それは追って調べる。