I am having some issues installing mongodb driver for PHP on MacOS. The PHP I have on my laptop came with MacOS and the version is:

PHP 7.1.19 (cli) (built: Aug 17 2018 20:10:18) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

I have followed instructions on disabling csrutil and installed pear with the following command:

curl -O http://pear.php.net/go-pear.phar 
sudo php -d detect_unicode=0 go-pear.phar

And then I am trying to install mongodb with the following command:

sudo pecl install mongodb

The problem now is that the compilation fails with "include file not found" error. I have Xcode development and command line tools installed and have looked all over for answers but I can't seem to crack this error.

While installing the include paths are found by pecl (as shown below) but when it comes to compiling it is erroring out as below:

/usr/include/php/ext/pcre/php_pcre.h:29:10: fatal error: 'pcre.h' file not found

include "pcre.h"


Following a suggestion on the web I even included the path to header files with C_INCLUDE_PATH but doesn't work.

checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib checking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20160303 checking for PHP installed headers prefix... /usr/include/php

Can someone please throw some light on this? I am at my wit's end on this :)


I was able to resolve this issue. Although php_pcre.h file was located in the include path, pcre.h wasn't.

I ran the install with the following command (setting the path for pcre header files) and that did the trick:

sudo C_INCLUDE_PATH=/usr/local/opt/pcre pecl install mongodb


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.