LoginSignup
10
5

More than 5 years have passed since last update.

mac の phpenv で php 7.1.9 をインストールするメモ

Last updated at Posted at 2018-01-24

クリーンインストール済みの OSX el capitan に anyenv をインストールして、 anyenv にインストールした phpenv から php 7.1.9 をインストールした。

何度もやってるけど、忘れてしまうことが多いのでメモ。

インストール

インストール可能な一覧を知るために以下のコマンドを実行し、一覧からインストールしたいバージョンを探す。


$ phpenv install --list
  7.1.8
  7.1.9
  7.1snapshot
  7.2.0
  7.2.1
  7.2snapshot
  master

今回はとりあえず 7.1.9 をインストールするので $ phpenv install 7.1.9 を実行する。

で実行すると以下のように BUILD ERROR となった。

$ phpenv install 7.1.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 2.3, min: 204, excluded: ).
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: Cannot find OpenSSL's <evp.h>
-----------------------------------------

エラー3つ。

  • bison のバージョンが低いよ
  • re2c が必要だよ
  • openssl の evp.h が見つからないよ

ってことらしい。

bision, re2c は brew からインストールして、 openssl のエラーは PHP_BUILD_CONFIGURE_OPTS を指定して解決する。

以下のコマンドでインストールして、 bison は link する。

$ brew install bison
$ brew link bison --force
$ brew install re2c
$ brew install openssl

必要そうなものをインストールしたので、以下のコマンドで再度 7.1.9 のインストールを試みる。

$ PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.1.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
configure: error: jpeglib.h not found.
-----------------------------------------

PHP_BUILD_CONFIGURE_OPTS 環境変数を用いて、 openssl の path を指定している。

で、またもエラー。

libjpeg がないから生じているらしい。

と、言うことで brew からインストールする。

$ brew install libjpeg

で再び php 7.1.9 のインストール。

$ PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.1.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
configure: error: png.h not found.
-----------------------------------------

libpng がないから生じているらしい。

と、言うことで brew からインストールする。

$ brew install libpng

で再び php 7.1.9 のインストール。

$ PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.1.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
-----------------------------------------

icu4c がないから生じているらしい。

と、言うことで brew からインストールする。

また、 link もしておく。

$ brew install icu4c
$ brew link icu4c --force
Linking /usr/local/Cellar/icu4c/60.2... 61 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile

で再び php 7.1.9 のインストール。

$ PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.1.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
-----------------------------------------

mcrypt がないから生じているらしい。

と、言うことで brew からインストールする。

$ brew install mcrypt

で再び php 7.1.9 のインストール。

$ PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.1.9

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
^
1 warning generated.
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
-----------------------------------------

autoconf がないから生じているらしい。

と、言うことで brew からインストールする。

$ brew install autoconf

で再び php 7.1.9 のインストール。

$ PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.1.9

[Success]: Built 7.1.9 successfully.

インストールできた!

ついでにインストールした php 7.1.9 に対して composer をインストールする。

まずは global の php のバージョンを 7.1.9 にする。

$ phpenv global 7.1.9
$ php --version
PHP 7.1.9 (cli) (built: Jan 15 2018 03:25:19) ( NTS )

次に、 composer コマンドを実行すると自動的にダウンロードされる。

$ composer --version
$ composer
Download composer.phar ...
All settings correct for using Composer
Downloading...

Composer (version 1.6.2) successfully installed to: /Users/hokutoasari/composer.phar
Use it: php ./composer.phar
Composer version 1.6.2 2018-01-05 15:28:41

参考資料:

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