🔖

Mac Big Sur、phpenv で PHP 7.4, 7.3 を再インストール(intl のビルドエラーがあり解決)

2021/05/04に公開

2022年3月25日に brew update したところ、もう下記の手順ではPHP 8.0 以下がビルドできなくなってしまいました(8.1以上しかインストールできませんでした)。phpbrew でもビルドできなかったので、今は homebrew の PHP を こちらの方法 で使っています。個人開発では Docker を使っています。


問題

Mac Big Sur (11.2.2)、phpenv (anyenv) 環境下で、自分が入れていた全バージョンが実行エラーになっており壊れていた。

解決

  • PHP v8 は、単に再インストールを試みたら正常に完了できたので、ノートラブルだった
  • PHP v7.4 と v7.3 の方は、ビルド手順に下記を加えることにより再インストールができるようになった

CFLAG と CXXFLAG に -DU_DEFINE_FALSE_AND_TRUE=1-Wno-error=implicit-function-declaration を加えた

$ export CFLAGS="-Wno-error=implicit-function-declaration -DU_DEFINE_FALSE_AND_TRUE=1"
$ export CXXFLAGS="-Wno-error=implicit-function-declaration -DU_DEFINE_FALSE_AND_TRUE=1"

コンフィギュアオプションの方は特に変更なし(壊れる前と同じ内容のものを使用):

$ export PHP_BUILD_CONFIGURE_OPTS="--with-external-gd=$(brew --prefix gd) \
--enable-intl --enable-sockets --enable-exif --with-zlib \
--with-zlib-dir=$(brew --prefix zlib) --with-bz2 --with-bz2=$(brew --prefix bzip2) \
--with-iconv=$(brew --prefix libiconv) --with-kerberos \
--with-openssl=$(brew --prefix openssl) --enable-soap --enable-xmlreader --with-xsl \
--enable-ftp --enable-cgi --with-pgsql=$(brew --prefix postgres) \
--with-libedit=$(brew --prefix libedit) --with-tidy --with-xmlrpc --enable-sysvsem \
--enable-sysvshm --enable-shmop --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-pdo-sqlite --enable-pcntl --with-readline --enable-mbstring --disable-debug \
--enable-fpm --enable-bcmath --enable-phpdbg --with-pear --with-pgsql \
--with-pdo-pgsql --with-sodium"
$ phpenv install --ini development 7.3.9
(・・・省略・・・)
[xdebug]: Installing version 3.0.2
[Skipping]: Already downloaded http://xdebug.org/files/xdebug-3.0.2.tgz
[xdebug]: Compiling xdebug in /var/tmp/php-build/source/xdebug-3.0.2
[xdebug]: Cleaning up.
Makefile:230: warning: overriding commands for target `test'
Makefile:134: warning: ignoring old commands for target `test'
[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.7.3.9.20210504111900.log or rebuild with '--verbose' option
[Success]: Built 7.3.9 successfully.
phpenv: cannot rehash: /Users/nana/.anyenv/envs/phpenv/shims/.phpenv-shim exists
$ phpenv local 7.3.9
$ pecl install redis
$ pecl install amqp

以下、詳細(失敗、試行錯誤の記録)

原因は分からなかった

何をしたら問題が起こったのかを思い出すことはできなかった。Homebrew を更新したからか?という気はするけれど、覚えていない。

実行エラーになったときの内容

変更前は、icu4c v67 でビルドしていた。(執筆時点現在、homebrew では v69 がデフォルト)

$ php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.67.dylib
  Referenced from: /Users/nana/.anyenv/envs/phpenv/versions/7.3.9/bin/php
  Reason: image not found
[1]    55414 abort      php -v

以前の設定のままでビルドしたときのエラー内容

  • intl でビルドエラー:
$ icu-config --version
69.1
$ phpenv install 7.3.9                                                     phpenv: /Users/nana/.anyenv/envs/phpenv/versions/7.3.9 already exists
continue with installation? (y/N) y
[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.3.9 into /Users/nana/.anyenv/envs/phpenv/versions/7.3.9
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-7.3.9.tar.bz2
[Preparing]: /var/tmp/php-build/source/7.3.9
[Compiling]: /var/tmp/php-build/source/7.3.9

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

Here are the last 10 lines from the log:

-----------------------------------------
2 warnings generated.
/var/tmp/php-build/source/7.3.9/ext/intl/collator/collator_sort.c:349:26: error: use of undeclared identifier 'TRUE'
        collator_sort_internal( TRUE, INTERNAL_FUNCTION_PARAM_PASSTHRU );
                                ^
/var/tmp/php-build/source/7.3.9/ext/intl/collator/collator_sort.c:543:26: error: use of undeclared identifier 'FALSE'
        collator_sort_internal( FALSE, INTERNAL_FUNCTION_PARAM_PASSTHRU );
                                ^
2 errors generated.
make: *** [ext/intl/collator/collator_sort.lo] Error 1
make: *** Waiting for unfinished jobs....
-----------------------------------------

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

[NGだったやり方!] homebrew で入れている icu4c を v68, v66 にダウングレードしてみる

ref.Homebrewで過去のバージョンを使いたい【tap版】 - Carpe Diem

$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
$ git log --follow icu4c.rb
 commit 5eec73f8ca76c547053c84162ec83794c22f01a1
Author: FX Coudert <fxcoudert@gmail.com>
Date:   Wed Dec 9 17:36:49 2020 +0000

    icu4c: update 67.1 bottle. 
$ brew extract icu4c kumamidori/taps --version 67.1
$ brew install kumamidori/taps/icu4c@67.1
(※使っている Zsh でパスを通す)
$ vi ~/dotfiles/.zsh/.env
(下記を追記)
export PATH="/usr/local/opt/icu4c@67.1/bin:$PATH"
$ . ~/.zshrc
$ brew install kumamidori/taps/icu4c@67.1

$ export PHP_BUILD_CONFIGURE_OPTS="(※長いので省略・・・)"
$ phpenv install --ini development 7.3.9

※uninstall したい場合は
brew uninstall kumamidori/taps/icu4c@67.1
tap 削除したい場合は
brew untap kumamidori/taps
とする。

[NGだったやり方!] CXXFLAGS、CFLAGを環境変数で設定してみるだけ(警告無視は未設定)

$ export CXXFLAGS=-DU_DEFINE_FALSE_AND_TRUE=1
$ export CFLAGS=-DU_DEFINE_FALSE_AND_TRUE=1
$ export PHP_BUILD_CONFIGURE_OPTS="(※長いので省略・・・)"
$ phpenv install --ini development 7.3.9
  • 別のエラーでビルド失敗:
(・・・省略・・・)
[Compiling]: /var/tmp/php-build/source/7.3.9

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

Here are the last 10 lines from the log:

-----------------------------------------
1 error generated.
make: *** [main/reentrancy.lo] Error 1
make: *** Waiting for unfinished jobs....
/var/tmp/php-build/source/7.3.9/main/network.c:240:42: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                        host_info = php_network_gethostbyname(host);
                                                              ^~~~
main/php_network.h:322:56: note: passing argument to parameter 'name' here
PHPAPI struct hostent*  php_network_gethostbyname(char *name);
                                                        ^
1 warning generated.
-----------------------------------------

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

[NGだったやり方!] XCode をダウングレードしてみる

  • 変更前の時と同じ intl エラーでビルド失敗

Discussion