LoginSignup
8
6

More than 5 years have passed since last update.

phpenvで複数PHPインストール

Last updated at Posted at 2016-05-03

前提条件

  • Vagrant
  • CentOS6系

phpenvインストール

$ mkdir ~/src
$ cd ~/src
$ git clone https://github.com/CHH/phpenv.git
$ cd phpenv/bin
$ ./phpenv-install.sh
Installing phpenv in /home/vagrant/.phpenv
remote: Counting objects: 2057, done.
Receiving objects: 100% (2057/2057), 344.17 KiB | 556 KiB/s, done.
remote: Total 2057 (delta 0), reused 0 (delta 0), pack-reused 2057
Resolving deltas: 100% (1272/1272), done.
Success.

export PATH="/home/vagrant/.phpenv/bin:$PATH"
eval "$(phpenv init -)"

Add above line at the end of your ~/.bashrc and restart your shell to use phpenv.

設定

$ vi ~/.bashrc

追記
-----------------------------------------------
export PATH="/home/vagrant/.phpenv/bin:$PATH"
eval "$(phpenv init -)"
-----------------------------------------------

php-buildインストール

php-buildのプラグインとしてインストール

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

PHPインストール

ライブラリ等インストール

$ yum repolist all | grep epel

- epelがenabled出ない場合、epelリポジトリインストール
$ sudo yum install wget
$ wget http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ sudo yum localinstall epel-release-6-8.noarch.rpm

$ sudo yum install gcc bison httpd-devel libxml2 libxml2-devel openssl-devel \
libcurl-devel libjpeg-turbo-devel libpng-devel libmcrypt-devel \
readline-devel libtidy-devel libxslt-devel re2c freetype-devel

PHPコンパイルオプション設定

$ vi /home/vagrant/.phpenv/plugins/php-build/share/php-build/definitions/5.5.22
削除
-----------------------------------------------
install_pyrus                                  
-----------------------------------------------

$ vi /home/vagrant/.phpenv/plugins/php-build/share/php-build/default_configure_options
追記
-----------------------------------------------
--with-apxs2=/usr/sbin/apxs                    
--with-freetype-dir=/usr                       
-----------------------------------------------

メモ書き)
php-buildで同じバージョンをコンパイルオプションを変更して、PHPをインストールするときは、PHPビルド前ソースコードを削除したほうがいいかも。Makefileとかは下記に存在。

$ rm -rf /tmp/php-build/source/5.5.22 

php-buildのスクリプト修正

下記パーミッションエラーが出るので、スクリプト修正

/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /usr/lib64/httpd/modules
cp: cannot create regular file `/usr/lib64/httpd/modules/libphp5.so': Permission denied
apxs:Error: Command failed with rc=65536

libphp5.soの出力場所を~/.phpenv/versions/5.5.22/へ変更。

ただし、下記参考パッチが最新バージョンのphp-buildではあてられないパッチになっているのと、後ほど出てくるphpenv-apache-versionを想定していないので、独自にパッチ作成

参考)
http://tkuchiki.hatenablog.com/entry/2014/04/08/210022

$ wget https://gist.githubusercontent.com/orangehat/04e5a16daccbf5493c6d4d3da3a58dc1/raw/96df8cfcc0aaac444a08ba871c6223842b5aa00c/php-build.patch
$ patch -u ~/.phpenv/plugins/php-build/bin/php-build < php-build.patch

phpenvからPHPインストール

$ phpenv install 5.5.22

phpenv-apache-versionインストール

$ git clone https://github.com/garamon/phpenv-apache-version ~/.phpenv/plugins/phpenv-apache-version

PHP切り替え

$ cd /path/to/project
$ sudo /home/vagrant/.phpenv/bin/phpenv apache-version 5.5.22
8
6
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
8
6