Fixing the dreaded "'pcre2.h' file not found" error when installing imagick original

by Freek Van der Herten – 1 minute read

Whenever I upgrade PHP, I seem to have troubles installing imagick. This command

pecl install imagick

always results in an error "'pcre2.h' file not found".

To fix that error, you should issue these commands:

brew install pcre2
ln -s /opt/homebrew/Cellar/pcre2/10.39/include/pcre2.h /opt/homebrew/Cellar/php/8.1.0_1/include/php/ext/pcre/pcre2.h

You should probably replace the version numbers in that second command. Find out the version numbers by cd'ing into the /opt/homebrew/Cellar/pcre2/ and /opt/homebrew/Cellar/php/ directories.

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Found something interesting to share? Submit a link to the community section.