phpenvをインストールしてバージョン単位に管理
概要
phpenvというツールをインストールしてphpをインストーしたバージョン単位に切り替えられるようにする
手順
phpenvをインストール
# phpenvをインストール
[root@localhost ~]# cd
[root@localhost ~]# curl https://raw.github.com/CHH/phpenv/master/bin/phpenv-install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 2833 101 2833 0 0 4834 0 --:--:-- --:--:-- --:--:-- 13685
Installing phpenv in /root/.phpenv
remote: Counting objects: 1715, done.
remote: Compressing objects: 100% (716/716), done.
remote: Total 1715 (delta 1112), reused 1516 (delta 967)
Receiving objects: 100% (1715/1715), 251.09 KiB | 151 KiB/s, done.
Resolving deltas: 100% (1112/1112), done.
Success.
[root@localhost ~]#
環境変数に設定
[root@localhost ~]# echo 'export PATH="$HOME/.phpenv/bin:$PATH"' >> ~/.bash_profile
[root@localhost ~]# echo 'eval "$(phpenv init -)"' >> ~/.bash_profile
環境設定の再ロード
[root@localhost ~]# source ~/.bash_profile
インストール場所の確認
[root@localhost ~]# which phpenv
/root/.phpenv/bin/phpenv
[root@localhost ~]#
コマンドを叩いて確認
[root@localhost ~]# phpenv
rbenv 0.4.0-65-gff23666
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme
[root@localhost ~]#
php-buildのインストール
[root@localhost ~]# mkdir -p /root/.phpenv/plugins
[root@localhost ~]# cd /root/.phpenv/plugins
[root@localhost plugins]# git clone git://github.com/CHH/php-build.git
Initialized empty Git repository in /root/.phpenv/plugins/php-build/.git/
remote: Counting objects: 1817, done.
remote: Compressing objects: 100% (754/754), done.
remote: Total 1817 (delta 946), reused 1751 (delta 892)
Receiving objects: 100% (1817/1817), 258.57 KiB | 224 KiB/s, done.
Resolving deltas: 100% (946/946), done.
[root@localhost plugins]# curl https://raw.github.com/hnw/php-build/plugin-to-chh-phpenv/bin/rbenv-install > php-build/bin/rbenv-install
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
112 560 112 560 0 0 1429 0 --:--:-- --:--:-- --:--:-- 2403
[root@localhost plugins]#
実行権限を付与
[root@localhost plugins]# chmod 755 php-build/bin/rbenv-install
インストールするものを確認
[root@localhost plugins]# phpenv install
usage: phpenv install VERSION
Available versions:
5.2.17
5.3.10
5.3.11
5.3.11RC1
5.3.11RC2
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.19RC1
5.3.2
5.3.20
5.3.20RC1
5.3.21
5.3.22
5.3.23
5.3.24
5.3.25
5.3.26
5.3.27
5.3.3
5.3.6
5.3.8
5.3.9
5.3.9RC3
5.3.9RC4
5.3snapshot
5.4.0
5.4.0RC1
5.4.0RC2
5.4.0RC3
5.4.0RC4
5.4.0RC5
5.4.0RC6
5.4.0RC7
5.4.0RC8
5.4.0alpha3
5.4.0beta1
5.4.0beta2
5.4.1
5.4.10
5.4.10RC1
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.1RC1
5.4.1RC2
5.4.2
5.4.20
5.4.3
5.4.4
5.4.5
5.4.6
5.4.7
5.4.8
5.4.9
5.4.9RC1
5.4snapshot
5.5.0
5.5.0RC1
5.5.0RC2
5.5.0RC3
5.5.0alpha1
5.5.0alpha2
5.5.0alpha3
5.5.0alpha4
5.5.0alpha5
5.5.0alpha6
5.5.0beta1
5.5.0beta2
5.5.0beta3
5.5.0beta4
5.5.1
5.5.2
5.5.3
5.5.4
5.5snapshot
[root@localhost plugins]#
依存するモジュールをインストール
[root@localhost plugins]# yum --enablerepo=epel install re2c
[root@localhost plugins]# yum --enablerepo=epel install libmcrypt
[root@localhost plugins]# yum --enablerepo=epel install libmcrypt-devel
[root@localhost plugins]# yum install libxml2-devel
[root@localhost plugins]# yum install bison
[root@localhost plugins]# yum install bison-devel
[root@localhost plugins]# yum install openssl-devel
[root@localhost plugins]# yum install curl-devel
[root@localhost plugins]# yum install libjpeg-devel
[root@localhost plugins]# yum install libpng-devel
[root@localhost plugins]# yum install libmcrypt-devel
[root@localhost plugins]# yum install readline-devel
[root@localhost plugins]# yum install libtidy-devel
[root@localhost plugins]# yum install libxslt-devel
[root@localhost plugins]# yum install httpd-devel
[root@localhost plugins]# yum install enchant-devel
[root@localhost plugins]# yum install libXpm
[root@localhost plugins]# yum install libXpm-devel
[root@localhost plugins]# yum install freetype-devel
[root@localhost plugins]# yum install t1lib t1lib-devel
[root@localhost plugins]# yum install gmp-devel
[root@localhost plugins]# yum install libc-client-devel
[root@localhost plugins]# yum install libicu-devel
[root@localhost plugins]# yum install oniguruma-devel
[root@localhost plugins]# yum install net-snmp
[root@localhost plugins]# yum install net-snmp-devel
[root@localhost plugins]# yum install bzip2-devel
phpの5.3.27をインストール
「vim /root/.phpenv/plugins/php-build/share/php-build/definitions/5.3.27」で編集
configure_option "--with-apxs2=/usr/sbin/apxs --disable-fpm --enable-fileinfo --enable-hash --enable-json --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-iconv --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --enable-phar --enable-shmop --enable-sockets --enable-simplexml --enable-dom --with-libxml-dir=/usr --enable-tokenizer --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --without-mm --with-enchant=/usr --with-zlib-dir=/usr --with-gd --enable-gd-native-ttf --with-gmp=/usr --with-jpeg-dir=/usr --with-xpm-dir=/usr/X11R6 --with-png-dir=/usr --with-freetype-dir=/usr --with-imap=/usr --with-imap-ssl --enable-intl --with-t1lib=/usr --with-mcrypt=/usr --with-snmp=/usr"
install_package "http://php.net/distributions/php-5.3.27.tar.bz2"
install_pyrus
install_xdebug "2.2.3"
インストール実行
[root@localhost ~]# phpenv install 5.3.27
[Info]: Loaded apc Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.3.27 into /root/.phpenv/versions/5.3.27
[Downloading]: http://php.net/distributions/php-5.3.27.tar.bz2
[Preparing]: /tmp/php-build/source/5.3.27
[Compiling]: /tmp/php-build/source/5.3.27
[Pyrus]: Downloading from http://pear2.php.net/pyrus.phar
[Pyrus]: Installing executable in /root/.phpenv/versions/5.3.27/bin/pyrus
[XDebug]: Downloading http://xdebug.org/files/xdebug-2.2.3.tgz
[XDebug]: Compiling in /tmp/php-build/source/xdebug-2.2.3
[XDebug]: Installing XDebug configuration in /root/.phpenv/versions/5.3.27/etc/conf.d/xdebug.ini
[XDebug]: Cleaning up.
[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.3.27.20131005122333.log
[Success]: Built 5.3.27 successfully.
[root@localhost ~]#
モジュールを退避する
[root@localhost ~]# mv /etc/httpd/modules/libphp5.so /root/.phpenv/versions/5.3.27/
[root@localhost ~]#
phpの5.4.20をインストール
「vim /root/.phpenv/plugins/php-build/share/php-build/definitions/5.4.20」で編集
configure_option "--with-apxs2=/usr/sbin/apxs --enable-fpm --enable-fileinfo --enable-hash --enable-json --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-iconv --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --enable-phar --enable-shmop --enable-sockets --enable-simplexml --enable-dom --with-libxml-dir=/usr --enable-tokenizer --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --without-mm --with-enchant=/usr --with-zlib-dir=/usr --with-gd --enable-gd-native-ttf --with-gmp=/usr --with-jpeg-dir=/usr --with-xpm-dir=/usr/X11R6 --with-png-dir=/usr --with-freetype-dir=/usr --with-imap=/usr --with-imap-ssl --enable-intl --with-t1lib=/usr --with-mcrypt=/usr --with-snmp=/usr"
install_package "http://php.net/distributions/php-5.4.20.tar.bz2"
install_pyrus
install_xdebug "2.2.3"
インストール実行
[root@localhost ~]# phpenv install 5.4.20
[Info]: Loaded apc Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.4.20 into /root/.phpenv/versions/5.4.20
[Downloading]: http://php.net/distributions/php-5.4.20.tar.bz2
[Preparing]: /tmp/php-build/source/5.4.20
[Compiling]: /tmp/php-build/source/5.4.20
[Pyrus]: Downloading from http://pear2.php.net/pyrus.phar
[Pyrus]: Installing executable in /root/.phpenv/versions/5.4.20/bin/pyrus
[XDebug]: Downloading http://xdebug.org/files/xdebug-2.2.3.tgz
[XDebug]: Compiling in /tmp/php-build/source/xdebug-2.2.3
[XDebug]: Installing XDebug configuration in /root/.phpenv/versions/5.4.20/etc/conf.d/xdebug.ini
[XDebug]: Cleaning up.
[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.4.20.20131005124559.log
[Success]: Built 5.4.20 successfully.
[root@localhost ~]#
モジュールを退避する
[root@localhost ~]# mv /etc/httpd/modules/libphp5.so /root/.phpenv/versions/5.4.20/
[root@localhost ~]#
phpの5.5.4をインストール
「vim /root/.phpenv/plugins/php-build/share/php-build/definitions/5.5.4」で編集
configure_option "--with-apxs2=/usr/sbin/apxs --enable-fpm --enable-fileinfo --enable-hash --enable-json --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-iconv --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --enable-phar --enable-shmop --enable-sockets --enable-simplexml --enable-dom --with-libxml-dir=/usr --enable-tokenizer --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --without-mm --with-enchant=/usr --with-zlib-dir=/usr --with-gd --enable-gd-native-ttf --with-gmp=/usr --with-jpeg-dir=/usr --with-xpm-dir=/usr/X11R6 --with-png-dir=/usr --with-freetype-dir=/usr --with-imap=/usr --with-imap-ssl --enable-intl --with-t1lib=/usr --with-mcrypt=/usr --with-snmp=/usr"
install_package "http://www.php.net/distributions/php-5.5.4.tar.bz2"
install_pyrus
install_xdebug "2.2.3"
enable_builtin_opcache
インストール実行
[root@localhost ~]# phpenv install 5.5.4
[Info]: Loaded apc Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.5.4 into /root/.phpenv/versions/5.5.4
[Downloading]: http://www.php.net/distributions/php-5.5.4.tar.bz2
[Preparing]: /tmp/php-build/source/5.5.4
[Compiling]: /tmp/php-build/source/5.5.4
[Pyrus]: Downloading from http://pear2.php.net/pyrus.phar
[Pyrus]: Installing executable in /root/.phpenv/versions/5.5.4/bin/pyrus
[XDebug]: Downloading http://xdebug.org/files/xdebug-2.2.3.tgz
[XDebug]: Compiling in /tmp/php-build/source/xdebug-2.2.3
[XDebug]: Installing XDebug configuration in /root/.phpenv/versions/5.5.4/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.5.4.20131005130728.log
[Success]: Built 5.5.4 successfully.
[root@localhost ~]#
モジュールを退避する
[root@localhost ~]# mv /etc/httpd/modules/libphp5.so /root/.phpenv/versions/5.5.4/
[root@localhost ~]#
apacheの設定を変更(vim /etc/httpd/conf/httpd.conf)
#LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so ←ここをコメントアウト
新しく拡張モジュールとして「vim /etc/httpd/conf.d/php.conf」で定義ファイルを作成
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
LoadModule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
PHP(cli)のバージョンの確認
[root@localhost ~]# phpenv rehash
[root@localhost ~]# php -v
rbenv: php: command not found
The `php' command exists in these Ruby versions:
5.3.27
5.4.20
5.5.4
[root@localhost ~]#
※「phpenv rehash」を初回に実行
※まだ、切り替えていない場合はインストールしたバージョンのリストを表示する
とりあえず、5.5.4に切り替え
[root@localhost ~]# phpenv global 5.5.4
[root@localhost ~]# php -v
PHP 5.5.4 (cli) (built: Oct 5 2013 13:22:14)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
[root@localhost ~]#
apacheなどで切り替えられるようにphpenv-apache-versionインストール
[root@localhost ~]# git clone https://github.com/garamon/phpenv-apache-version ~/.phpenv/plugins/phpenv-apache-version
Initialized empty Git repository in /root/.phpenv/plugins/phpenv-apache-version/.git/
remote: Counting objects: 36, done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 36 (delta 10), reused 31 (delta 5)
Unpacking objects: 100% (36/36), done.
[root@localhost ~]#
確認用のサンプルスクリプトを作成
[root@localhost ~]# vim /var/www/html/info.php
----
<?php
phpinfo();
----
切り替え確認
5.5.4に切り替え
[root@localhost ~]# phpenv apache-version 5.5.4
copy /root/.phpenv/versions/5.5.4/libphp5.so to /etc/httpd/modules
Restarting apache...
Stopping httpd: [ OK ]
Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[ OK ]
[root@localhost ~]#
phpinfo
5.4.20に切り替え
[root@localhost ~]# phpenv apache-version 5.4.20
copy /root/.phpenv/versions/5.4.20/libphp5.so to /etc/httpd/modules
Restarting apache...
Stopping httpd: [ OK ]
Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[ OK ]
[root@localhost ~]#
phpinfo
最終更新:2013年10月05日 21:49