Fixing the "fatal error: 'pcre2.h' file not found" Issue

PHPmacOSpcre2

In macOS, when using pecl to install some extensions, you will encounter

fatal error: 'pcre2.h' file not found

error, this error is more commonly encountered on macOS;

The root cause is that PHP did not find the pcre2 dependency, so the solution is very simple:

brew install pcre2

Then link this pcre2.h file to PHP using a soft link

ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /opt/homebrew/Cellar/php/8.1/include/php/ext/pcre/pcre2.h

Note: You need to modify the paths of pcre2 and php

Finally, re-execute the pecl installation command.