LoginSignup
19
19

More than 5 years have passed since last update.

CentOSにphpenvでPHP環境を構築する

Last updated at Posted at 2014-04-05

環境

  • CentOS 6.6
  • rbenv 導入済み
  • git 導入済み

準備

phpenvのインストール

cd /usr/local/src
curl https://raw.github.com/CHH/phpenv/master/bin/phpenv-install.sh | bash
vi ~/.bash_profile
~/.bash_profile
PATH=$HOME/.rbenv/bin:$PATH
PATH=$HOME/.phpenv/bin:$PATH
PATH=$PATH:$HOME/bin

eval "$(rbenv init -)"
eval "$(phpenv init -)"
source ~/.bash_profile

php-buildの導入

git clone https://github.com/CHH/php-build.git ~/.phpenv/plugins/php-build

php-buildの更新

cd ~/.phpenv/plugins/php-build
git reset --hard && git pull

バージョンを指定したPHPのインストール

今回はPHP5.5.22をインストールする(2015/3/26 PHP5.5系最新)

インストール可能なPHPのバージョンを調べる

phpenv install

依存関係にあるパッケージを導入する

yum --enablerepo=rpmforge install re2c libmcrypt-devel
yum install bison libxml2-devel libcurl-devel libjpeg-devel libpng-devel readline-devel libtidy-devel libxslt-devel

ビルド時のオプションを変更する

PHPをビルドする時のオプションは~/.phpenv/plugins/php-build/share/php-build/default_configure_optionsに記述されている。これは全体のオプションでどのバージョンにも適用される。

設定可能なオプションはPHP: 中心となる configure オプションのリストを参考

カレントディレクトリのphp.iniを読み込むようにする

vi ~/.phpenv/plugins/php-build/share/php-build/definitions/5.5.22
5.5.22
configure_option "--with-config-file-scan-dir=.;/root/.phpenv/versions/5.5.22/etc/conf.d"

httpd用のモジュールを作成する

デフォルトではhttpd用のモジュールであるlibphp5.soが作成されないので、バージョンを指定してオプションを変更する

vi ~/.phpenv/plugins/php-build/share/php-build/definitions/5.5.22

以下の行を先頭に追加する

5.5.22
configure_option "--with-apxs2=/usr/bin/apxs"

intl拡張モジュールを有効にする

vi ~/.phpenv/plugins/php-build/share/php-build/definitions/5.5.22
5.5.22
configure_option "--enable-intl"

インストール

phpenv install 5.5.22

PHPのバージョンを切り替える

phpenv global 5.5.22
phpenv rehash

参考

  1. モダンなPHP開発環境を構築する – phpenv + php-build で 複数のPHPバージョンを管理する | Creator Life
  2. php-buildで複数バージョンのPHP-FPMを用意する - hnwの日記
19
19
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
19
19