07/09/2018, 16:03

Multiple version management on PHP

Summary Phpenv provides to manage versions on PHP You can use php with version which you want Its installing is easier than make install Switching version is only one command First Phpenv is use 'rbenv' what is management system on Ruby. On switching version, phpenv calls rbenv. ...

Summary

  • Phpenv provides to manage versions on PHP
  • You can use php with version which you want
  • Its installing is easier than make install
  • Switching version is only one command

First

Phpenv is use 'rbenv' what is management system on Ruby.
On switching version, phpenv calls rbenv.
Then, it switches link to php binary file.

Phpenv has bad habit what conflicts rbenv.
If phpenv picked up it, rbenv is disabled.
(Perhaps it's not use ruby on the system)
Of course, this introduction's way avoids it.

Process of installation

Above way is for CentOs 6.5
If you use other version or OS,
Pleaes replace to correct way.

Setup ruby environment

$ git clone https://github.com/sstephenson/rbenv.git ~/rbenv

Set Path

Phpenv requests to call bootstrap command.

Therefore, I made common script
which is called by all user on login.

$vi /etc/profile.d/env.sh

Then, write below lines.

export RBENV_ROOT="/usr/local/rbenv"
PATH="$RBENV_ROOT/bin:$PATH"
export PATH
eval "$(rbenv init -)"

After wrote it, let's execute it.

$ source /etc/profile.d/env.sh
$ echo $PATH

And confirm to show path to rbenv

usr/local/rbenv/bin:/usr/local/rbenv/shims:/usr/local/rbenv/bin: ...

Install ruby

Ruby-build provide installing some version of ruby.
Then, install ruby!

$ cd ~/rbenv
$ mkdir ./plugins
$ cd ./plugins
$ git clone https://github.com/sstephenson/ruby-build.git ./ruby-build
$ cd ./ruby-build/

# install
./install.sh

After install ruby-build, installing of rbenv is completed.
Then, you can install all version of ruby, and use it.
Usage is following.

# show all versions you can do
$ rbenv install --list

# install
$ rbenv install x.x.x

# apply ruby to system
$ rbenv global x.x.x

NOTE: 'x.x.x' is ruby's version what you want.

If you done above process,
you may use ruby.

$ ruby -v
> ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

Setup php

The way of phpenv is same as rbenv.

Clone phpenv

git clone https://github.com/CHH/phpenv.git ~/.phpenv

Note: above script is installation file

Install phpenv

Before intstall phpenv, set path of phpenv's core.

# Set path
$ export RBENV_ROOT="/usr/local/phpenv"

# Confirming
$ echo $RBENV_ROOT

# Install
$ cd ./.phpenv/bin/

$ phpenv-install.sh

Note: In this time, I install php into /usr /local

Set path

As rbenv's setup, it also needs to edit shell file in /etc/profile.d.

$ vi /etc/profile.d/env.sh

Rewrite the shell-script.

#rbenv
export RBENV_ROOT="/usr/local/rbenv"
PATH="$RBENV_ROOT/bin:$PATH"

#phpenv
export PHPENV_ROOT="/usr/local/phpenv
PATH="$PATH:$PHPENV_ROOT/bin"

export PATH
eval "$(rbenv init -)"
eval "$(phpenv init -)"

Please exec it and confirm path.

$ source /etc/profile.d/env.sh
$ echo $PATH
> /usr/local/rbenv/bin:/usr/local/rbenv/shims: ... /usr/local/phpenv/bin:/root/bin:/usr/local/phpenv/bin

Install php-build

Next, install the system manages each version of php.

$ cd /usr/local/phpenv
$ mkdir ./plugins
$ cd ./plugins
$ git clone https://github.com/CHH/php-build.git ./php-build
./install.sh

Install packages related with php

Installing PHP requests some packages.
I used packaging system on CentOS to install these.

If you use system other than CentOS,
Please use appropriate packaging manager.

epel

yum localinstall http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Install php

After install php-build, installing of php is completed.
Then, you can install all version of php, and use it.
Usage is following.

# show all versions you can do
$ phpenv install --releases

# install
$ php install x.x.x

# apply php to system
$ php global x.x.x

If you done above process,
let's try next command.

$ php -v
> PHP 5.6.5 (cli) (built: Feb 16 2015 17:49:35)

Could you see php version?

Appendix

Switch version

Rbenv and phpenv can switch versions.
Usage is following.

$ rbenv global x.x.x
$ phpenv gloabal x.x.x

If you don't know installed version,
please use following command.
You can see all of versions installed

$ phpenv/rbenv versions

Using compile options

hp-build uses compiling source code when it isntalls php each version.
If you want to use options when it install,
please do to following steps.

$ vi ~/.phpenv/plugins/php-build/share/php-build/definitions/x.x.x

In this file, please write options you want.
Example is following.

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"

PHP.ini

Each binary file of php is independent.
And, php.ini file is too.

The file's path is following.

/usr/local/phpenv/versions/X.X.X/etc/php.ini

You have to set configure each versions.
Please remember this rule.

Finally

Phpenv provides us to support detailed version management on PHP.

If new version is release, you may try it without overwrite currently version.

Or, unfortunately, you have to use older server with lower than php 5.4
,Phpenv may be help you.

This article may be not enough to use PHP. ;(

It's necessary that PHP works on web-server with phpenv.

ON next time,
I gona write about it!

0