LoginSignup
0
0

More than 5 years have passed since last update.

phpenvを使わないで複数のバージョンのPHPを共存させる方法

Last updated at Posted at 2016-07-20

前提

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が上手くいかない原因は知りたいから、それは追って調べる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0