2020年5月3日日曜日

[PHP] macOS Catalina で phpenv install のエラーでハマった

新しいMacをゲット。
環境設定を実施し始めたのだが、phpenv installでハマってしまったので メモ。


背景

さまざま環境設定をし、Homebrewもインストール、anyenv -> phpenv とインストールし、いざPHPの特定バージョンをインストールしようと以下を実行。
phpenv install 7.2.24

エラーがまあまあ出たが、 ひとつづつ解決していく


error: Cannot find xxxxx

Cannot find( 見つかりません)という単純なエラー

[Preparing]: /var/tmp/php-build/source/7.2.24

-----------------
|  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: error: Cannot find zlib
-----------------------------------------

この手のエラーは特に問題なくHomebrewで、インストールしながら解決していく
brew install zlib

これでOK


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

こういうエラー
[Preparing]: /var/tmp/php-build/source/7.2.24

-----------------
|  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: error: Cannot find OpenSSL's <evp.h>
-----------------------------------------
これは、Catalina (Mojaveものようだが)になって、これまでできていたヘッダーファイルのありか(/usr/include)が作成されなくなるという仕様変更によるもののようで、ヘッダーファイルが探せないからのようだ。

この手のエラーはPHP_BUILD_CONFIGURE_OPTSなどで 回避ができるようになっており、以下のように指定をして実行すると良い。
PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl) --with-libxml-dir=$(brew --prefix libxml2)" PHP_BUILD_EXTRA_MAKE_ARGUMENTS=-j4 phpenv install 7.2.24


特にハマったエラー error: Please reinstall the libcurl distribution

順調にエラーを回避していたのだが、最終的にこのエラーに一番悩まされた。
[Preparing]: /var/tmp/php-build/source/7.2.24

-----------------
|  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: Fallback: search for curl headers and curl-config
configure: error: Please reinstall the libcurl distribution -
      easy.h should be in <curl-dir>/include/curl/

-----------------------------------------
curl入ってるしなと思いながらいろいろ参考文献を探したが、分からず。。。
これも結局は

結局最終的にはPHP_BUILD_CONFIGURE_OPTSを指定することで回避ができた。


最終的に

以下のコマンドを実行することで無事インストールが できた。

// 7.2.24 インストール
PHP_BUILD_CONFIGURE_OPTS="--with-libedit=$(brew --prefix libedit) --with-curl=$(brew --prefix curl) --with-libcurl=$(brew --prefix curl) --with-openssl=$(brew --prefix openssl) --with-libxml-dir=$(brew --prefix libxml2)" PHP_BUILD_EXTRA_MAKE_ARGUMENTS=-j4 phpenv install 7.2.24

[Success]: Built 7.2.24 successfully.


// 7.1.8 もインストールできました
PHP_BUILD_CONFIGURE_OPTS="--with-libedit=$(brew --prefix libedit) --with-curl=$(brew --prefix curl) --with-libcurl=$(brew --prefix curl) --with-openssl=$(brew --prefix openssl) --with-libxml-dir=$(brew --prefix libxml2)" PHP_BUILD_EXTRA_MAKE_ARGUMENTS=-j4 phpenv install 7.1.8

[Success]: Built 7.1.8 successfully.