PHPBrewでintl拡張をインストール

1. 環境

インストールする環境はこんな感じ

$ sw_vers
ProductName:	macOS
ProductVersion:	11.3
BuildVersion:	20E232

$ phpbrew --version
phpbrew - 1.27.0
cliframework core: 2.5.4

$ phpbrew list
* php-7.4.13
  php-7.3.25

$ php -v
PHP 7.4.13 (cli) (built: Dec  4 2020 21:48:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

icu4c はインストール済

$ brew install icu4c

2. インストール

まずは失敗したケースから

$ phpbrew ext install intl
===> Installing intl extension...
Log stored at: /Users/admin/.phpbrew/build/php-7.4.13/ext/intl/build.log
Changing directory to /Users/admin/.phpbrew/build/php-7.4.13/ext/intl
===> Phpize...
===> Configuring...
Error: Command failed: ./configure '--with-php-config=/Users/admin/.phpbrew/php/php-7.4.13/bin/php-config' >> '/Users/admin/.phpbrew/build/php-7.4.13/ext/intl/build.log' 2>&1 returns:

エラーログによると、pkg-config のために PKG_CONFIG_PATH が必要らしい

checking whether to enable internationalization support... yes, shared
checking for icu-uc >= 50.1 icu-io icu-i18n... no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ICU_CFLAGS
and ICU_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

どう設定すればいいのかを確認

$ brew info icu4c
icu4c: stable 69.1 (bottled) [keg-only]
C/C++ and Java libraries for Unicode and globalization
http://site.icu-project.org/home
/usr/local/Cellar/icu4c/69.1 (259 files, 72.8MB)
  Poured from bottle on 2021-04-27 at 21:48:00
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/icu4c.rb
License: ICU
 :
 :
 :
For pkg-config to find icu4c you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"
 :
 :
 :

改めてインストール

$ export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig
$ phpbrew ext install intl
===> Installing intl extension...
Log stored at: /Users/admin/.phpbrew/build/php-7.4.13/ext/intl/build.log
Changing directory to /Users/admin/.phpbrew/build/php-7.4.13/ext/intl
===> Phpize...
===> Configuring...
===> Building...
===> Running make all: /usr/bin/make -C '/Users/admin/.phpbrew/build/php-7.4.13/ext/intl' 'all'  >> '/Users/admin/.phpbrew/build/php-7.4.13/ext/intl/build.log' 2>&1
===> Installing...
===> Running make install: /usr/bin/make -C '/Users/admin/.phpbrew/build/php-7.4.13/ext/intl' 'install'  >> '/Users/admin/.phpbrew/build/php-7.4.13/ext/intl/build.log' 2>&1
===> Extension is installed.
===> Creating config file /Users/admin/.phpbrew/php/php-7.4.13/var/db/intl.ini.disabled
===> Enabling extension intl
[*] intl extension is enabled.
Done.
$ phpbrew ext |grep intl
 [*] intl         7.4.13

3. iniの場所

$ ls ~/.phpbrew/php/php-7.4.13/var/db/intl.ini
/Users/admin/.phpbrew/php/php-7.4.13/var/db/intl.ini