swoole-src: Compile Error on Mac Big Sur with PHP 8

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error. Install swoole pecl install swoole

  2. What did you expect to see? swoole pecl extension

  3. What did you see instead? Compile termination error

In file included from /private/tmp/pear/temp/swoole/ext-src/php_swoole.cc:21:
/usr/local/Cellar/php/8.0.0_1/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~
1 error generated.
make: *** [ext-src/php_swoole.lo] Error 1
ERROR: `make' failed
  1. What version of Swoole are you using (show your php --ri swoole)?
pecl install swoole
downloading swoole-4.5.9.tgz ...
Starting to download swoole-4.5.9.tgz (1,552,445 bytes)
..................................................................................................................................................................................................................................................................................................................done: 1,552,445 bytes
351 source files, building
running: phpize
Configuring for:
PHP Api Version:         20200930
Zend Module Api No:      20200930
Zend Extension Api No:   420200930
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_6

PHP 8.0.0 (cli) (built: Nov 30 2020 13:51:52) ( NTS ) Copyright © The PHP Group Zend Engine v4.0.0-dev, Copyright © Zend Technologies with Zend OPcache v8.0.0, Copyright ©, by Zend Technologies

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 28 (3 by maintainers)

Most upvoted comments

I can get it work by manually symlink the required file.

ln -s /usr/local/Cellar/pcre2/10.36/include/pcre2.h /usr/local/Cellar/php/8.0.0_1/include/php/ext/pcre/pcre2.h

https://github.com/swoole/swoole-src/issues/3926#issuecomment-744763791

For me the paths were different, this worked:

ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre/pcre2.h

I had similar problem with PHP 7.4 on Mac M1, but changing the versions in the code above did not work. Thepcre2.h file was in a different directory all together, once i found the correct location it compiled.

$ ln -s /opt/homebrew/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.16/include/php/ext/pcre/pcre2.h

This worked for me with PHP 8.0.5 and pcre2 10.36:

ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.5/include/php/ext/pcre/

in my case it solved with: php 8.0.6 pcre2 10.36

ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.6_1/include/php/ext/pcre/

For my case I did this in my Mac M1:

brew list pcre2 | grep 'pcre2\.h$'

This will output the path to pcre2 as shown below:

/opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h

Then

ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.30/include/php/ext/pcre/pcre2.h

Be sure to replace the php path with your php version && path.

Hopefully this helps someone.

If you just installed php using Brew without specifying a version, the path might be slightly different (again). This is the command I had to run:

 sudo ln -s /opt/homebrew/include/pcre2.h /opt/homebrew/Cellar/php/X.X.X/include/php/ext/pcre/pcre2.h 

(where X.X.X is the PHP version, in my case 8.1.4)

ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include/php/ext/pcre/pcre2lib/pcre2.h /opt/homebrew/Cellar/php/8.0.3/include/php/ext/pcre/pcre2.h

ITS SAVED ME, THANKS!!!♥️

thanks

ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include/php/ext/pcre/pcre2lib/pcre2.h /opt/homebrew/Cellar/php/8.0.3/include/php/ext/pcre/pcre2.h

and then

Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.0.3/include/php/ext/swoole/config.h'
Installing '/opt/homebrew/Cellar/php/8.0.3/pecl/20200930/swoole.so'
install ok: channel://pecl.php.net/swoole-4.6.4
Extension swoole enabled in php.ini

Thanks, guys. In my case it solved it a symlink:

ln -s /opt/homebrew/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.24/include/php/ext/pcre/pcre2.h

All that you need is check your php version and path. In case of pcre2 is not installed, install it with:

brew install pcre2

Environment and Case: Macbook M1 with Big Sur trying to install imagick extension with PHP 7.4

Just to simplify for others, where X - installed php version sudo ln -s /opt/homebrew/include/pcre2.h /opt/homebrew/Cellar/php@X.X/X.X.X/include/php/ext/pcre/pcre2.h

Try installing pcre2 to the system before:

brew install pcre2

But I guess it can cause Swoole to be compiled with a different version of PCRE library than PHP’s.

Thanks, guys, you saved my time!

$ ln -s /opt/homebrew/Cellar/pcre2/10.37/include/pcre2.h /opt/homebrew/Cellar/php/8.0.7/include/php/ext/pcre/pcre2.h

#3926 (comment)

For me the paths were different, this worked:

ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre/pcre2.h

OK,if Your system version is : MacOS Big Sur 11.6 and is M1 ,This is useful… Thanks …

#3926 (comment)

For me the paths were different, this worked:

ln -s /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre/pcre2.h

Thank you it was helpful, I did it for php 8.0.8_1 and it worked.

ln -s /opt/homebrew/Cellar/pcre2/10.37_1/include/pcre2.h /opt/homebrew/Cellar/php/8.0.8_1/include/php/ext/pcre/pcre2.h
  1. restart apache
  2. sudo pecl install mongodb