Edited at

Macにphpbrewを入れてphpのバージョン管理

More than 1 year has passed since last update.


この記事について

Macにphpの開発環境を整えたい、かつ、phpのバージョン管理もしたいのでphpbrewを入れることにした話。主に作業時のコマンドのメモ。

phpbrew本家→ https://github.com/phpbrew/phpbrew


要点


  • Homebrew は最新に保とう brew upgrade brew update 等で


手順


brew install phpbrew で失敗

いきなりインストールコマンドで失敗

$ brew install phpbrew

エラーメッセージは以下

Error: /usr/local/Library/Taps/homebrew/homebrew-php/Formula/phpbrew.rb:35: syntax error, unexpected <<

def caveats; <<~EOS
^
/usr/local/Library/Taps/homebrew/homebrew-php/Formula/phpbrew.rb:38: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
Please report this bug:
https://git.io/brew-troubleshooting
/usr/local/Library/Homebrew/formulary.rb:21:in `module_eval'
/usr/local/Library/Homebrew/formulary.rb:21:in `load_formula'
/usr/local/Library/Homebrew/formulary.rb:38:in `load_formula_from_path'
/usr/local/Library/Homebrew/formulary.rb:87:in `load_file'
/usr/local/Library/Homebrew/formulary.rb:78:in `klass'
/usr/local/Library/Homebrew/formulary.rb:74:in `get_formula'
/usr/local/Library/Homebrew/formulary.rb:211:in `factory'
/usr/local/Library/Homebrew/formulary.rb:356:in `find_with_priority'
/usr/local/Library/Homebrew/extend/ARGV.rb:20:in `block in formulae'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `map'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in `formulae'
/usr/local/Library/Homebrew/cmd/install.rb:100:in `install'
/usr/local/Library/brew.rb:87:in `<main>'

とりあえずbrewを最新版にするために

$ phpbrew upgrade

$ phpbrew update

を実行。この過程でエラーが発生したがそれは別記事を書いた→ https://qiita.com/makito/items/4204ef5c4ce8e80ed535

こっちも参考→ brew updateをしたらError: /usr/local must be writable!が出た

その後

$ brew install phpbrew

バージョン確認

$ phpbrew -version

...
phpbrew 1.22.5 powered by https://github.com/c9s/CLIFramework


初期設定

本家のREADMEに沿って https://github.com/phpbrew/phpbrew#getting-started 初期設定を実施

$ phpbrew init

インストール可能なバージョンを確認

$ phpbrew known

7.2: 7.2.2, 7.2.1, 7.2.0 ...
7.1: 7.1.14, 7.1.13, 7.1.12, 7.1.11, 7.1.10, 7.1.9, 7.1.8, 7.1.7 ...
7.0: 7.0.27, 7.0.26, 7.0.25, 7.0.24, 7.0.23, 7.0.22, 7.0.21, 7.0.20 ...
5.6: 5.6.33, 5.6.32, 5.6.31, 5.6.30, 5.6.29, 5.6.28, 5.6.27, 5.6.26 ...
5.5: 5.5.37, 5.5.36, 5.5.35, 5.5.34, 5.5.33, 5.5.32, 5.5.31, 5.5.30 ...
5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 ...

7.1系を入れたいので 7.1.14 を入れる

$ phpbrew install 7.1.14 +default

7.1.14 に切り替え

$ phpbrew use php-7.1.14

$ php -version
PHP 7.1.14 (cli) (built: Feb 24 2018 09:37:29) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies