在 macOS 中,用 pecl 安装一些扩展的时候,会碰到

fatal error: 'pcre2.h' file not found

的报错,这个报错在 macOS 上比较常遇到;

根本原因是 PHP 没有找到 pcre2 依赖,所以解决方法就很简单了:

brew install pcre2

然后把这个 pcre2.h 文件,用软链接的方式链接到 PHP

ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /opt/homebrew/Cellar/php/8.1/include/php/ext/pcre/pcre2.h
注意:你需要修改 pcre2 和 php 的路径

最后重新执行 pecl 安装命令就可以了。

打赏不准超过你工资的一半!!!