yellow and black stripes

Pecl: fixing “fatal error: ‘pcre2.h’ file not found”

Written by

in

When using pecl to install a PHP extension, I always got a “fatal error: ‘pcre2.h’ file not found” after PHP has been updated. The update was done using brew upgrade php. In my case, this happens when I try to install pcov using:

pecl install pcov

The output was:

In file included from /private/tmp/pear/temp/pcov/pcov.c:26:
/opt/homebrew/Cellar/php/8.2.2/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~

To fix the issue, make sure you have pcre2 installed:

brew install pcre2

After this, create a symlink to the pcre2.h file:

ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/php/8.2.2/include/php/ext/pcre/pcre2.h

Make sure, to adjust the versions of pcre2 and php (or any other package where you got the error). In my case it’s PHP version 8.2.2 (see the error message) and pcre2 version 10.42.

After the symlink was created, the installation of pcov finished without errors:

Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.2.2/pecl/20220829/pcov.so'
install ok: channel://pecl.php.net/pcov-1.0.11
Extension pcov enabled in php.ini

What is PECL?

PECL stands for PHP Extension Community Library. It’s a repository for PHP extensions that are written in C code and provide additional functionality to PHP. These extensions can be compiled and added to PHP to enhance its capabilities. PECL hosts a wide range of extensions, from database connections to cryptography tools, and much more. Developers often use PECL to extend PHP’s functionality beyond what’s available in its core libraries.

Foto von Scott Rodgerson auf Unsplash.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *