phpenvを使ってMacにPHPをインストールするのは毎回ハマってます。
これまではネットの情報を集めて何とかインストールできたんですが、今回はMac OS 15.1と新しめなOSのせいか、Arm64アーキテクチャのせいか分かりませんが、ネットの情報だけではなかなか解決できず、とりあえず、以下のようにしてPHP 8.1.30のインストールができました。
grepをbrewでインストール
$ brew install grep
そうすると、ggrepというコマンドが /opt/homebrew/bin/
にインストールされるので、これをgrepと置き換えるために、とりあえず、$HOME/bin にリンクを貼ってパスを通します
$ ln -s `which ggrep` $HOME/bin/grep
$ export PATH=$HOME/bin:$PATH
これをやっておかないと、以下のようなエラーが出ます
grep: invalid option -- P
usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
必要なライブラリのインストール
必要なライブラリはよく分からないのですが、ネットの情報でとりあえず以下のライブラリ群をbrewでインストール
$ brew install libyaml autoconf bzip2 icu4c@74 krb5 libedit libiconv libjpeg libpng libxml2 libzip oniguruma openssl pkg-config tidy-html5 libxslt pcre2
icu4c@74とバージョン指定しているのは、このバージョンより新しいものを指定しすると、以下のようにC++でのコンパイル時に大量のエラーが出るから。
-----------------
| BUILD ERROR |
-----------------
Here are the last 10 lines from the log:
-----------------------------------------
| ~~~~~^
/opt/homebrew/Cellar/icu4c@76/76.1_1/include/unicode/unistr.h:2299:40: error: no template named 'enable_if_t' in namespace 'std'
2299 | template<typename S, typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
| ~~~~~^
/opt/homebrew/Cellar/icu4c@76/76.1_1/include/unicode/unistr.h:3273:40: error: no template named 'enable_if_t' in namespace 'std'
3273 | template<typename S, typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
| ~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
make: *** [ext/intl/calendar/calendar_methods.lo] Error 1
-----------------------------------------
ビルドの実行
必要な環境変数をセットして実行します。ちょっと長いですが、以下のようになりました。
PKG_CONFIG_PATH=/opt/homebrew/opt/icu4c@74/lib/pkgconfig CXXFLAGS="-std=c++14" CPP_FLAGS=$(pkg-config --cflags libjpeg) LD_FLAGS=$(pkg-config --libs libjpeg) PHP_BUILD_CONFIGURE_OPTS="--with-tidy=$(brew --prefix tidy-html5) --with-jpeg=$(brew --prefix jpeg) --with-zlib-dir=$(brew --prefix zlib) --with-bz2=$(brew --prefix bzip2) --with-curl=$(brew --prefix curl) --with-iconv=$(brew --prefix libiconv) --with-libedit=$(brew --prefix libedit) " phpenv install 8.1.30
これでビルドが成功しました。
ちなみに、8.2系のコンパイルは、以下のエラーが出てしまい、うまく行かないようです。
configure: error: *** A compiler with support for C++17 language features is required.
うまく行った人いたら教えてください。