Installing mongodb driver for PHP on MacOS

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

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 :)

profilepic.png
manpreet 2 years ago

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

Phew!

 

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.