LoginSignup
6
8

More than 5 years have passed since last update.

phpbrewでphpバージョン管理をはじめる。

Last updated at Posted at 2017-02-28
  • mac PCでのセットアップ手順メモ(備忘のために検索してあちこちに散らばっていたtipsをまとめてみた)。
  • 前提としてhomebrewを使う環境があること

1. phpbrewをインストール

homebrewに登録されている以下のレポジトリを自分のローカルPCで利用できるようにする

[~] brew tap homebrew/versions
[~] brew tap homebrew/php
[~] brew tap homebrew/dupes

その後
brew install phpbrewでインストール。phpbrew initを実行するように、などと指示が出るので適宜やっておく。

2. 試しに最新バージョンのphp(7.1.2)を入れてみる

[~] phpbrew known
7.1: 7.1.2, 7.1.0 ...
7.0: 7.0.16, 7.0.15, 7.0.14, 7.0.13, 7.0.12, 7.0.11, 7.0.10, 7.0.9 ...
5.6: 5.6.30, 5.6.29, 5.6.28, 5.6.27, 5.6.26, 5.6.25, 5.6.24, 5.6.23 ...
5.5: 5.5.38, 5.5.37, 5.5.36, 5.5.35, 5.5.34, 5.5.33, 5.5.32, 5.5.31 ...
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 ...
[~] phpbrew install 7.1.2

configure: error: OpenSSL version 1.0.1 or greater required.

こんなエラーが出た。下記のようにして解決する

[~] brew --prefix openssl
/usr/local/opt/openssl
[~] phpbrew install 7.1.2 +openssl=/usr/local/opt/openssl
* To configure your installed PHP further, you can edit the config file at
    /Users/daiando/.phpbrew/php/php-7.1.2/etc/php.ini

To use the newly built PHP, try the line(s) below:

    $ phpbrew use php-7.1.2

Or you can use switch command to switch your default php to php-7.1.2:

    $ phpbrew switch php-7.1.2

Enjoy!

なが〜い間待たされてようやくインストールできた。ワンライナーにするとこんな感じ。
phpbrew install 7.1.2 +openssl=$(brew --prefix openssl)

3. warningが出る時の対処

早速バージョン確認

[~] phpbrew list
* (system)
  php-7.1.2
[~] php -v
PHP 7.0.15 (cli) (built: Jan 22 2017 08:51:45) ( NTS )
[~] phpbrew switch php-7.1.2
[~] php -v
PHP 7.1.2 (cli) (built: Feb 28 2017 22:58:12) ( NTS )
[~] phpbrew list
WARNING: json extension is required for downloading release info.
WARNING: curl extension might be required for fetching data.
* php-7.1.2

これで7.1.2が使えるようになっている。
しかし、phpbrew listでもう一度インストールされたphpバージョンを確認すると、jsonとcurlのエクステンションが無い、という警告が出た。警告を消したいので、下記のように対処した。

[~] phpbrew ext install json
[~] phpbrew ext install curl
[~] phpbrew list
* php-7.1.2
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8