11

I try to install openswoole on my mac machine. I have this issue when installing it.

/usr/local/Cellar/php@7.4/7.4.29/include/php/ext/pcre/php_pcre.h:25:10: fatal error: pcre2.h: No such file or directory
 #include "pcre2.h"

I used the command brew install pcre to fix this issue as others recommend, but I always get the same result. I try to open the folder pcre I only see one php_pcre.h file inside it.

user3818576
  • 2,979
  • 8
  • 37
  • 62

4 Answers4

32

Here's simplest solution. I have finally solved my problem. I used PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)

My errors: fatal error: 'pcre2.h' file not found

The solution that I used:

  1. brew install pcre2

  2. ln -s /opt/homebrew/opt/pcre2/include/pcre2.h /opt/homebrew/opt/php@8.1/include/php/ext/pcre/

    Beware of the PHP version in the destination, adjust as-needed. Then, re-run the installation that failed, e.g. apcu or openswoole.

  3. pecl install ...

Success Installation:

enter image description here

Hope it help you :) Thanks

Timo Tijhof
  • 10,032
  • 6
  • 34
  • 48
Alex
  • 3,646
  • 1
  • 28
  • 25
4

try:

sudo ln -s /opt/local/include/pcre.h /usr/include/       "replace your file location here"
sudo pecl install apc 
debugger
  • 1,442
  • 1
  • 9
  • 14
  • thanks for the idea. I get it now. I just change the location of the folder to link the pcr2.h. I have this location folder `/usr/local/Cellar/php@7.4/7.4.29/include/php/ext/pcre` – user3818576 Apr 28 '22 at 06:53
  • 2
    for future help this resolved my problem https://freek.dev/2151-fixing-the-dreaded-pcre2h-file-not-found-error-when-installing-imagick which is similar – Theofanis May 04 '22 at 19:41
2

For M1 MacBooks, this is how I fixed that error when installing rdkafka.

pecl install rdkafka

Error

/Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~

Solution

ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/pcre2.h

See the new link

➜ cd /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre
➜ ls -l
total 8
lrwxr-xr-x  1 ddhondup  admin    48 Oct  6 15:29 pcre2.h -> /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h
-rw-rw-r--  1 ddhondup  admin  3970 Oct  1  2021 php_pcre.h

After adding the link, it worked.

Build process completed successfully
Installing '/Applications/MAMP/bin/php/php8.0.8/lib/php/extensions/no-debug-non-zts-20200930/rdkafka.so'
install ok: channel://pecl.php.net/rdkafka-6.0.3
configuration option "php_ini" is not set to php.ini location
You should add "extension=rdkafka.so" to php.ini
Dorjee Dhondup
  • 549
  • 6
  • 15
  • If brew install librdkafka did not work, try https://github.com/confluentinc/confluent-kafka-python/issues/1025#issuecomment-827675182 – Dorjee Dhondup Oct 06 '22 at 20:52
0

for me the path was different, I needed to find it by

brew --cellar

and then exact command above

 ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/php@8.1/8.1.20/include/php/ext/pcre/pcre2.h

so you need to check pre version, php version and change the paths accordingly :)