LoginSignup
13
12

More than 5 years have passed since last update.

macOS Sierraにanyenv, phpenvでPHP7.1を入れる

Last updated at Posted at 2017-01-03

概要

Sierraをクリーンインストールしたから環境整えようと思った。
普通にphpenvでやろうと思ったけど調べてたらanyenvというものがあるらしいので使ってみる。
anyenvまわりは基本は公式サイト見てればOKなのでメモ代わり。

phpのビルド/インストール関係はちょいちょいエラーって大変だった。

環境

  • macOS Sierra 10.12.2
$ which php
/usr/bin/php
$ php -v
PHP 5.6.27 (cli) (built: Oct 23 2016 11:47:58)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

anyenvのインストール

基本的にはanyenvのREADMEの通り

$ git clone https://github.com/riywo/anyenv ~/.anyenv
$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(anyenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l

anyenv-updateのインストール

anyenv配下の**env、プラグインの更新を行ってくれる

基本的にはanyenv-updateのREADMEの通り

$ mkdir -p $(anyenv root)/plugins
$ git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update

phpenvのインストール

とても簡単

$ anyenv install phpenv
$ exec $SHELL -l

PHP7.1のビルド/インストール

$ phpenv install 7.1.0

何も考えずにやるとエラーになる

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

Here are the last 10 lines from the log:

-----------------------------------------
configure: WARNING: unrecognized options: --with-mysql
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>
-----------------------------------------

The full Log is available at '/tmp/php-build.7.1.0.20170103124237.log'.
[Warn]: Aborting build.

独自の定義を作成し、設定を変更する

$ cp ~/.anyenv/envs/phpenv/plugins/php-build/share/php-build/definitions/7.1.0 ~/.anyenv/envs/phpenv/plugins/php-build/share/php-build/definitions/my_7.1.0
$ vim ~/.anyenv/envs/phpenv/plugins/php-build/share/php-build/definitions/my_7.1.0
my_7.1.0
+ configure_option -D "--with-mysql"
+ configure_option -R "--with-openssl=/usr/local/opt/openssl"
install_package "https://secure.php.net/distributions/php-7.1.0.tar.bz2"
install_xdebug "2.5.0"
enable_builtin_opcache

をファイルの先頭に追加
下記の様に最後に追加しても認識されなかった

$ echo configure_option -D "--with-mysql" >> ~/.anyenv/envs/phpenv/plugins/php-build/share/php-build/definitions/my_7.1.0

足りないものをインストール

libjpeg〜libmcryptはre2c解決した後にエラーになった
autoconf,automakeはその後にエラーになった

$ brew install bison
$ brew link bison --force
$ brew install re2c
$ brew install libjpeg
$ brew install libpng
$ brew install libmcrypt
$ brew install autoconf
$ brew install automake

再度、独自定義でインストールする

めっちゃ時間かかるので暇つぶししながら

$ phpenv install my_7.1.0
[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded github Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: Loaded zendopcache Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building my_7.1.0 into /Users/hrs/.anyenv/envs/phpenv/versions/my_7.1.0
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-7.1.0.tar.bz2
[Preparing]: /var/tmp/php-build/source/my_7.1.0
[Compiling]: /var/tmp/php-build/source/my_7.1.0
[xdebug]: Installing version 2.5.0
[xdebug]: Compiling xdebug in /var/tmp/php-build/source/xdebug-2.5.0
[xdebug]: Installing xdebug configuration in /Users/hrs/.anyenv/envs/phpenv/versions/my_7.1.0/etc/conf.d/xdebug.ini
[xdebug]: Cleaning up.
[Info]: Enabling Opcache...
[Info]: Done
[Info]: The Log File is not empty, but the Build did not fail. Maybe just warnings got logged. You can review the log in /tmp/php-build.my_7.1.0.20170103152042.log
[Success]: Built my_7.1.0 successfully.
$ phpenv rehash
$ phpenv versions
* system (set by /Users/hrs/.anyenv/envs/phpenv/version)
  my_7.1.0

使用するPHPの切り替え

$ phpenv global my_7.1.0
my_7.1.0
$ php -v
PHP 7.1.0 (cli) (built: Jan  3 2017 15:32:50) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans

参考

13
12
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
13
12