Published on

PHP のインストールメモ

Authors

使用環境

  • CentOS 6.5
  • Vagrant 1.7.2

必要パッケージをインストール

$ sudo yum install -y git re2c libxml2-devel openssl-devel readline-devel libcurl-devel libjpeg-turbo-devel libpng-devel libmcrypt-devel libtidy-devel libxslt-devel

phpenv をインストール

$ curl <https://raw.githubusercontent.com/CHH/phpenv/master/bin/phpenv-install.sh> | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3128 100 3128 0 0 585 0 0:00:05 0:00:05 --:--:-- 16463
Installing phpenv in /home/vagrant/.phpenv
remote: Counting objects: 2065, done.
remote: Total 2065 (delta 0), reused 0 (delta 0), pack-reused 2065
Receiving objects: 100% (2065/2065), 350.18 KiB | 309 KiB/s, done.
Resolving deltas: 100% (1280/1280), 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.

phpenv を実行できるようにする

$ echo 'export PATH="/home/vagrant/.phpenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(phpenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

$ phpenv -v
rbenv 0.4.0-151-g83ac0fb

php-build をインストール

$ git clone <https://github.com/php-build/php-build.git> ~/.phpenv/plugins/php-build
$ phpenv install -l
Available versions:
 5.2.17
 5.3.10
 5.3.11
 5.3.12
 5.3.13
 5.3.14
 5.3.15
 5.3.16
 5.3.17
 5.3.18
 5.3.19
 5.3.2
 5.3.20
 5.3.21
 5.3.22
 5.3.23
 5.3.24
 5.3.25
 5.3.26
 5.3.27
 5.3.28
 5.3.29
 5.3.3
 5.3.6
 5.3.8
 5.3.9
 5.4.0
 5.4.1
 5.4.10
 5.4.11
 5.4.12
 5.4.13
 5.4.14
 5.4.15
 5.4.16
 5.4.17
 5.4.18
 5.4.19
 5.4.2
 5.4.20
 5.4.21
 5.4.22
 5.4.23
 5.4.24
 5.4.25
 5.4.26
 5.4.27
 5.4.28
 5.4.29
 5.4.3
 5.4.30
 5.4.31
 5.4.32
 5.4.33
 5.4.34
 5.4.35
 5.4.36
 5.4.37
 5.4.38
 5.4.39
 5.4.4
 5.4.40
 5.4.41
 5.4.42
 5.4.5
 5.4.6
 5.4.7
 5.4.8
 5.4.9
 5.4snapshot
 5.5.0
 5.5.1
 5.5.10
 5.5.11
 5.5.12
 5.5.13
 5.5.14
 5.5.15
 5.5.16
 5.5.17
 5.5.18
 5.5.19
 5.5.2
 5.5.20
 5.5.21
 5.5.22
 5.5.23
 5.5.24
 5.5.25
 5.5.26
 5.5.3
 5.5.4
 5.5.5
 5.5.6
 5.5.7
 5.5.8
 5.5.9
 5.5snapshot
 5.6.0
 5.6.1
 5.6.10
 5.6.2
 5.6.3
 5.6.4
 5.6.5
 5.6.6
 5.6.7
 5.6.8
 5.6.9
 5.6snapshot
 7.0.0alpha1
 master

現時点で最新の5.6.9をインストールする。(configureはデフォルトにしておく)

$ phpenv install 5.6.9
[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.6.9 into /home/vagrant/.phpenv/versions/5.6.9
[Downloading]: <http://php.net/distributions/php-5.6.9.tar.bz2
[Preparing]:> /tmp/php-build/source/5.6.9
[Compiling]: /tmp/php-build/source/5.6.9
[Pyrus]: Downloading from <http://pear2.php.net/pyrus.phar
[Pyrus]:> Installing executable in /home/vagrant/.phpenv/versions/5.6.9/bin/pyrus
[xdebug]: Installing version 2.3.2
[xdebug]: Compiling xdebug in /tmp/php-build/source/xdebug-2.3.2
[xdebug]: Installing xdebug configuration in /home/vagrant/.phpenv/versions/5.6.9/etc/conf.d/xdebug.ini
[xdebug]: Cleaning up.
[Info]: Enabling Opcache...
[Info]: Done
[Info]: The Log File is not empty, but the Build did not fail. Maybe just warnings got logged. You can review the log in /tmp/php-build.5.6.9.20150624001503.log
[Success]: Built 5.6.9 successfully.

インストール済みのphpバージョンを確認する

$ phpenv versions
5.6.9

インストールしたPHPのバージョンを確認する
$ php -v
rbenv: version `system' is not installed
エラーが発生したが,下記コマンドを実行していなかったためなので実行する
$ phpenv global 5.6.9

再度確認する
$ php -v
PHP 5.6.9 (cli) (built: Jun 24 2015 00:27:08)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

無事,PHP のインストールが完了しました ;-)