LoginSignup
11
10

More than 5 years have passed since last update.

phpbrew でPHP7 をインストールする。

Last updated at Posted at 2017-04-22

PHP 7のアプリケーション開発をするために、PHPをインストールしようとしたところ、以前はphpenvがhomebrewでインストールできたのですが、今では消えていました。
その代わりに、phpbrewが入っていたので、それを使ってインストール。

前提

  • macOS Sierra 10.12.4
  • homebrew はインストール済み
  • phpenvはインストールしてない

手順

$ brew tap homebrew/php
$ brew install phpbrew
$ phpbrew init

その後、利用してるシェルに合わせて、.bashrc などに下記の一行を追加。

 source /Users/hogehoge/.phpbrew/bashrc

その後、再度端末を開くか、シェルを起動し直しして、phpbrewが使えることを確認しましょう。

それが終わったら、現在インストール可能なPHPのバージョンをphpbrew known で取得し、実際に必要なバージョンをphpbrew install でインストールします。

$ phpbrew known
$ phpbrew install 7.0.18

という至って簡単なもの。のはずなんですが、最後のPHPのインストールで、次の2つの問題ではまりました。

インストールでハマったところ

BZip2 に必要なものがない

初回インストール時、下記のようなエラーが出ました。

checking if the location of ZLIB install directory is defined... no

checking whether to enable bc style precision math functions... yes

checking for BZip2 support... yes

checking for BZ2_bzerror in -lbz2... no

configure: error: bz2 module requires libbz2 >= 1.0.0

要するに、bzip2 ライブラリが無いというこなので、それをインストールする必要があります。
bzip2はもともとmacOSに入っているものなので、homebrewでは入れず、下記のように

$ xcode-select --install

その後、phpbrew install を再実行することでエラーが出なくなりました。

fatal error: 'openssl/evp.h' file not found

bzip2の問題の後、再度インストールを試したところ、次のエラーにが出ました。

/Users/hogehoge/.phpbrew/build/php-7.0.18/ext/openssl/openssl.c:44:10: fatal error: 'openssl/evp.h' file not found

#include <openssl/evp.h>

         ^

330 warnings and 1 error generated.

make: *** [ext/openssl/openssl.lo] Error 1

これも似たようなもので、エラーメッセージが示しているように、opensslのヘッダが見つからないという状態のため発生していました。
そこで、下記のようにopensslのヘッダファイルへのパスをphpbrew に渡すことで解決しました。

$ brew install openssl # Optional
$ phpbrew install 7.0.18 +default +openssl=$(brew --prefix openssl)

インストール完了!

$ phpbrew use php-7.0.18
$ php -v
PHP 7.0.18 (cli) (built: Apr 22 2017 23:17:46) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
$ phpbrew switch php-7.0.18
$ phpbrew list
* php-7.0.18

まだ使い始めたばかりではありますが、phpenvと少し違うところがありました。
以前にphpenvを利用した時はrbenvと共存させるために少し手間が必要だったのですが(phpenvとrbenvをMac共存させる - Qiita)、phpbrewだとそれが必要ありません。

参考

11
10
1

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
11
10