PHPのバージョンを管理するphpbrewを使ってみた

  • このエントリーをはてなブックマークに追加

バージョンの異なる実行環境を切り替えたり、インストールしたりと管理できるツールとしてはrvm(ruby)perlbrew(perl)nodebrew(node.js)と言ったものが有名所ですが、PHPにもphpbrewというツールがある事を知ったので使ってみました。

c9s/phpbrew · GitHub.

インストール

環境はMac OS X Lionです。
元々、入っているPHPのバージョンは5.3.8でPHP4.4.9はコンパイルして入れたものが入っています。

1
2
3
4
5
6
7
8
[suusuke@macbook ~]$ php -v
PHP 5.3.8 with Suhosin-Patch (cli) (built: Nov 15 2011 15:33:15)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
[suusuke@macbook ~]$ php4 -v
PHP 4.4.9 (cli) (built: Mar 26 2011 10:08:22)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

phpbrewインストール

c9s/phpbrew · GitHub に書いてある手順どおりインストールします。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[suusuke@macbook ~]$ sudo pear channel-discover pear.corneltek.com
Password:
Adding Channel "pear.corneltek.com" succeeded
Discovery of channel "pear.corneltek.com" succeeded
[suusuke@macbook ~]$ sudo pear install -a -f corneltek/PhpBrew
Password:
downloading PhpBrew-1.0.2.tgz ...
Starting to download PhpBrew-1.0.2.tgz (43,519 bytes)
............done: 43,519 bytes
downloading Universal-1.0.2.tgz ...
Starting to download Universal-1.0.2.tgz (10,805 bytes)
...done: 10,805 bytes
downloading CLIFramework-1.0.6.tgz ...
Starting to download CLIFramework-1.0.6.tgz (8,432 bytes)
...done: 8,432 bytes
downloading GetOptionKit-1.0.0.tgz ...
Starting to download GetOptionKit-1.0.0.tgz (10,801 bytes)
...done: 10,801 bytes
install ok: channel://pear.corneltek.com/Universal-1.0.2
install ok: channel://pear.corneltek.com/GetOptionKit-1.0.0
install ok: channel://pear.corneltek.com/CLIFramework-1.0.6
install ok: channel://pear.corneltek.com/PhpBrew-1.0.2
1
2
3
4
5
6
7
8
9
10
11
12
[suusuke@macbook ~]$ cd ~/
[suusuke@macbook ~]$ git clone git@github.com:c9s/phpbrew.git
Cloning into phpbrew...
Identity added: /Users/suusuke/ssh/github/id_rsa (/Users/suusuke/ssh/github/id_rsa)
remote: Counting objects: 1130, done.
remote: Compressing objects: 100% (436/436), done.
remote: Total 1130 (delta 676), reused 1014 (delta 560)
Receiving objects: 100% (1130/1130), 926.93 KiB | 244 KiB/s, done.
Resolving deltas: 100% (676/676), done.
[suusuke@macbook ~]$ cd phpbrew
[suusuke@macbook phpbrew]$ sudo pear install -f package.xml
install ok: channel://pear.corneltek.com/PhpBrew-1.1.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[suusuke@macbook ~]$ ./phpbrew init
Phpbrew environment is initialized, required directories are created under
 
    ~/.phpbrew
 
Paste the following line(s) to the end of your ~/.bashrc and start a
new shell, phpbrew should be up and fully functional from there:
 
    source ~/.phpbrew/bashrc
 
For further instructions, simply run `phpbrew` to see the help message.
 
Enjoy phpbrew at $HOME!!
[suusuke@macbook ~]$ source ~/.phpbrew/bashrc

インストールできるバージョンの確認

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[suusuke@macbook ~]$ ./phpbrew/phpbrew known
Available stable versions:
  php-5.4.0
  php-5.3.10
  php-5.3.9
  php-5.3.8
  php-5.3.7
  php-5.3.2
  php-5.3.1
Available svn versions:
  php-svn-head
  php-svn-5.3
  php-svn-5.4
Available versions from PhpStas:
  php-5.4.0
  php-5.4.0RC1
  php-5.4.0RC2
  php-5.4.0RC3
  php-5.4.0RC4
  php-5.4.0RC5
  php-5.4.0RC6
  php-5.4.0RC7
  php-5.4.0RC8
  php-5.4.0alpha1
  php-5.4.0alpha2
  php-5.4.0alpha3
  php-5.4.0beta1
  php-5.4.0beta2

インストールできるオプションの確認

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[suusuke@macbook ~]$ ./phpbrew/phpbrew variants
Variants
    pdo
    pear
    gd
    openssl
    mysql
    sqlite
    pgsql
    cli
    ftp
    sockets
    apxs2
    debug
    cgi
    soap
    pcntl
    intl
    imap
    kerberos
 
Example:
 
    phpbrew install php-5.3.10 +mysql +pdo
    phpbrew install php-5.3.10 +mysql +pdo +apxs2
    phpbrew install php-5.3.10 +mysql +pdo +apxs2=/usr/bin/apxs2

PHP5.4.0をインストールして使ってみる

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[suusuke@macbook ~]$ ./phpbrew/phpbrew -d install --no-test php-5.4.0
===> Downloading http://www.php.net/distributions/php-5.4.0.tar.bz2
######################################################################## 100.0%
===> Extracting...
===> Configuring php-5.4.0...
./configure '--prefix=/Users/suusuke/.phpbrew/php/php-5.4.0' '--with-config-file-path=/Users/suusuke/.phpbrew/php/php-5.4.0/etc' '--with-config-file-scan-dir=/Users/suusuke/.phpbrew/php/php-5.4.0/var/db' '--with-pear=/Users/suusuke/.phpbrew/php/php-5.4.0/lib/php' '--disable-all' '--enable-bcmath' '--enable-ctype' '--enable-dom' '--enable-exif' '--enable-fileinfo' '--enable-filter' '--enable-hash' '--enable-fpm' '--with-xsl' '--with-tidy' '--with-xmlrpc' '--enable-json' '--enable-libxml' '--enable-mbregex' '--enable-mbstring' '--enable-phar' '--enable-session' '--enable-short-tags' '--enable-simplexml' '--enable-sockets' '--enable-tokenizer' '--enable-xml' '--enable-xmlreader' '--enable-xmlwriter' '--enable-zip' '--with-bz2' '--with-mhash' '--with-pcre-regex' '--with-zlib=/opt/local' '--with-libxml-dir' '--with-curl=/opt/local' '--with-gettext=/opt/local' '--with-libedit=/usr' '--with-readline' '--enable-pdo' '--enable-cli'
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: bz2 module requires libbz2 >= 1.0.0
===> Building php-5.4.0...
make: *** No targets specified and no makefile found.  Stop.
Skip tests
Build finished: 0 minutes.
===> Installing...
---> Copying php.ini-development
Source directory:
Done!
To use the newly built PHP, try the line(s) below:
 
    $ phpbrew use php-5.4.0
 
Or you can use switch command to switch your default php version to php-5.4.0:
 
    $ phpbrew switch php-5.4.0

あれ!?

1
configure: error: bz2 module requires libbz2 >= 1.0.0

configureでエラーになる。。。

with-bz2オプションでlibbz2のパス指定すればいいのかなと思って、パラメータで指定してみたがnot definedとなって、パラメータでは指定できないみたい。。。

1
2
3
4
5
[suusuke@macbook ~]$ phpbrew -d install php-5.4.0 --with-bz2=/usr/lib/libbz2.dylib
===> Downloading http://www.php.net/distributions/php-5.4.0.tar.bz2
######################################################################## 100.0%
===> Extracting...
Variant --with-bz2 is not defined.

わからない。。。I don’t know…

追記

libbz2がインストールされてないんじゃないの?とコメント頂いたので、調べてみる。

1
2
[suusuke@macbook ~]$ ll /usr/lib/libbz2.dylib
lrwxr-xr-x  1 root  wheel  16  9 20 02:36 /usr/lib/libbz2.dylib -> libbz2.1.0.dylib

あるよね。。。
ホントに!?

macportsで調べる

1
2
3
4
5
6
[suusuke@macbook ~]$ sudo port installed
Password:
Warning: port definitions are more than two weeks old, consider using selfupdate
The following ports are currently installed:
  apache2 @2.2.10_0+darwin_9 (active)
  ...

macportsには無かった、取り合えずmacportsが古いといっているのでselfupdateしてmacportsで入れてみる。

1
2
3
[suusuke@macbook ~]$ sudo port -d selfupdate
[suusuke@macbook ~]$ sudo port upgrade outdated
[suusuke@macbook ~]$ sudo port upgrade installed

※途中port upgradeでmysqlのアップデートに失敗してmysqlがcleanされてしまい、コンパイルするのに一日費やしてしまった。。。

1
2
[suusuke@macbook ~]$ sudo port clean mysql5-devel
[suusuke@macbook ~]$ sudo port install mysql5-devel configure.compiler=llvm-gcc-4.2

コンパイラーをllvm-gcc-4.2するとコンパイルに成功した。

macports自信とライブラリをアップデートしたら、問題なくphpbrew -d install php-5.4.0に成功した。
bz2関連のライブラリが古かったのだろうか。。。。

  • このエントリーをはてなブックマークに追加

SNSでもご購読できます。

ads

コメントを残す

*