Macでphpenv + php-buildによる環境構築した際にハマった時のメモ（OpenSSLとか）

Mac(10.11, El Capitan)で[phpenv](https://github.com/CHH/phpenv)+[php-build](https://github.com/php-build/php-build)を使ってPHP環境を整えようとした時に地味にハマったので書き残しておく。

## エラー内容

phpenvとphp-buildは既に入っているとして、PHP5.5.27をインストールしようとしたら以下のエラーが出た。

```shell-session
$ phpenv install 5.5.27
[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.5.27 into /Users/foo/.phpenv/versions/5.5.27
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-5.5.27.tar.bz2
[Preparing]: /var/tmp/php-build/source/5.5.27

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

Here are the last 10 lines from the log:

-----------------------------------------
configure: error: Cannot find OpenSSL's <evp.h>
-----------------------------------------

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

`openssl`を入れてみるが"installed"とのこと。

```shell-session
$ brew install openssl
Warning: openssl already installed
```

多分バージョン変えたほうが良さそう。

## `openssl`のバージョンを変える

```shell-session
$ brew search openssl
homebrew/versions/openssl098				      openssl (installed)
homebrew/versions/openssl101
```

```shell-session
brew install homebrew/versions/openssl101
```

`openssl101`はkeg-onlyとのことなので自分で`brew link`する。

```shell-session
$ brew link --force homebrew/versions/openssl101
```

## PHPインストールしたらまたエラー

本記事で扱った依存関係以外については以下の記事参照。
http://qiita.com/tebonz/items/82ad7e57066650d43b28

```shell-session
$ phpenv install 5.5.27


[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.5.27 into /Users/foo/.phpenv/versions/5.5.27
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-5.5.27.tar.bz2
[Preparing]: /var/tmp/php-build/source/5.5.27
[Compiling]: /var/tmp/php-build/source/5.5.27

[Pyrus]: Downloading from http://pear2.php.net/pyrus.phar
[Pyrus]: Installing executable in /Users/foo/.phpenv/versions/5.5.27/bin/pyrus
[xdebug]: Installing version 2.3.3
[xdebug]: Compiling xdebug in /var/tmp/php-build/source/xdebug-2.3.3

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

Here are the last 10 lines from the log:

-----------------------------------------
1 warning generated.
/var/tmp/php-build/source/5.5.27/sapi/cli/php_cli_server.c:541:25: warning: address of '(sapi_globals.sapi_headers).headers' will always evaluate to 'true' [-Wpointer-bool-conversion]
        if (!&SG(sapi_headers).headers) {
            ~ ~~~~~~~~~~~~~~~~~^~~~~~~
1 warning generated.
/var/tmp/php-build/source/5.5.27/sapi/cgi/cgi_main.c:1700:25: warning: address of '(sapi_globals.sapi_headers).headers' will always evaluate to 'true' [-Wpointer-bool-conversion]
        if (!&SG(sapi_headers).headers) {
            ~ ~~~~~~~~~~~~~~~~~^~~~~~~
1 warning generated.
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
-----------------------------------------

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

↓を参考に`autoconf`と`automake`をインストール。ありがとうございました！
http://qiita.com/omega999/items/c5b1c177331f8d342efd

```shell-session
$ brew install autoconf
$ brew install automake
```

## ようやくインストール成功

```shell-session
$ phpenv install 5.5.27
[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.5.27 into /Users/foo/.phpenv/versions/5.5.27
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-5.5.27.tar.bz2
[Preparing]: /var/tmp/php-build/source/5.5.27
[Compiling]: /var/tmp/php-build/source/5.5.27
[Pyrus]: Downloading from http://pear2.php.net/pyrus.phar
[Pyrus]: Installing executable in /Users/foo/.phpenv/versions/5.5.27/bin/pyrus
[xdebug]: Installing version 2.3.3
[xdebug]: Compiling xdebug in /var/tmp/php-build/source/xdebug-2.3.3
[xdebug]: Installing xdebug configuration in /Users/foo/.phpenv/versions/5.5.27/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.5.5.27.20151014112846.log
[Success]: Built 5.5.27 successfully.
```
```shell-session
$ phpenv global 5.5.27
```
```shell-session
$ php -v
PHP 5.5.27 (cli) (built: Oct 14 2015 11:38:58)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
```