🐘

[Mac] phpenvで'buffio.h' file not foundと言われてPHP 7.0以下がインストールできない問題

2020/12/08に公開

はじめに

phpenvによるPHPのインストールは、インストールしようとするバージョンによって細かい対応が必要な場合があります。

以下のページに本ブログ内の関連記事をまとめていますので、必要に応じてご参照ください🙏

[2020年末版] Macでのphpenv(php-build)によるPHP 5.6〜8.0のインストール方法まとめ

Macのphpenv(php-build)で 'buffio.h' file not found と言われてPHP 7.0以下がインストールできない問題

ある日を境に、Macのphpenv(php-build)でPHP 7.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 7.0.33 into /Users/ttskch/.phpenv/versions/7.0.33
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-7.0.33.tar.bz2
[Preparing]: /var/tmp/php-build/source/7.0.33
[Compiling]: /var/tmp/php-build/source/7.0.33

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

Here are the last 10 lines from the log:

-----------------------------------------
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/php-build/source/7.0.33/ext/standard/streamsfuncs.c:1570:6: note: add parentheses after the '!' to evaluate the comparison first
/var/tmp/php-build/source/7.0.33/ext/standard/streamsfuncs.c:1570:6: note: add parentheses around left hand side expression to silence this warning
1 warning generated.
/var/tmp/php-build/source/7.0.33/ext/tidy/tidy.c:34:10: fatal error: 'buffio.h' file not found
#include "buffio.h"
         ^~~~~~~~~~
1 error generated.
make: *** [ext/tidy/tidy.lo] Error 1
make: *** Waiting for unfinished jobs....
-----------------------------------------

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

buffio.h が見つからないと言われていますが、SDKにはちゃんと buffio.h というファイルがあるようです🤔

原因

ググったら以下を見つけました。

どうやら、Homebrewで提供されている tidy-html5 というライブラリのバージョンが新しすぎるとこのエラーになるようです。

.phpenv/plugins/php-build/share/php-build/default_configure_options--with-tidy の記述がある ため、デフォルトで tidyエクステンション がインストールされ、そのプロセスでエラーになっているという状況です。

解決方法

tidyが何なのか知らなかったのですが、公式サイト を見ると

What is Tidy?

Tidy is a console application for Mac OS X, Linux, Windows, UNIX, and more. It corrects and cleans up HTML and XML documents by fixing markup errors and upgrading legacy code to modern standards.

libtidy is a C static and dynamic library that developers can integrate into their applications in order to bring all of Tidy’s power to your favorite tools. libtidy is used today in desktop applications, web servers, and more.

と書かれており、HTMLを整形するための機能を提供してくれるだけのもののようなので、今回は tidy自体をインストールしない ことでエラーを回避したいと思います。

参考:PHPで壊れたHTMLを整形する - Qiita

具体的には、php-buildのビルドオプションを指定するための環境変数 PHP_BUILD_CONFIGURE_OPTS--without-tidy を渡してビルドを実行すればよいです。

phpenvの場合なら、他に必要なオプションも含めると以下のようなインストールコマンドになります。

PHP_BUILD_CONFIGURE_OPTS="--with-zlib-dir=/usr/local/opt/zlib --with-bz2=/usr/local/opt/bzip2 --with-jpeg-dir=/usr/local/opt/libjpeg --with-png-dir=/usr/local/opt/libpng --with-curl=/usr/local/opt/curl --with-iconv=/usr/local/opt/libiconv --with-libedit=/usr/local/opt/libedit --without-tidy" phpenv install 7.0.33

もしtidyをインストールしたいのであれば、Homebrewでインストールしている tidy-html5 のバージョンを下げる 必要があると思います。

参考:

どのバージョンまで下げればインストールできるようになるのかは確認していませんので、実際に試した方がいたら 教えていただけると嬉しいです🙏

以上です!

GitHubで編集を提案

Discussion