必要に迫られたのでphpbrewでPHPをM1でインストールしようと試みた。試していないけど多分phpenvとかでも起きるかも。
$ phpbrew install -j (nproc) 7.4 +default
以下エラーが出る。
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. Fatal error: Uncaught InvalidArgumentException: RegexIterator::__construct(): Allocation of JIT memory failed, PCRE JIT will be disabled. This is likely caused by security restrictions. Either grant PHP permission to allocate executable memory, or set pcre.jit=0 in /path/to/.phpbrew/build/php-7.4.22/ext/phar/phar.php:1133
PCRE周りでエラーが出ているけど、PHP標準PCREはJITがデフォルト有効だけどM1がJIT未対応だからエラーになっていると思われる。
ので、Qiitaにも書いてあるとおりな感じで、ってやってJIT無効なPCREライブラリをパス指定するしかない。
phpbrew install -j (nproc) 7.4 +default -- --with-external-pcre=(brew --prefix pcre2)
ちなみにM1でだけJIT無効にするようにPCRE2のFormulaにも書いてある。