2
votes

I am running OSX El Capitan. I have installed the mongo driver using brew:

brew install php70-mongodb

The installation finished and it seems to work. When I do "php -m" on CLI it shows "mongo" installed. Running a script with Mongo driver works. The problem occurs when I am trying to run the same script through via Apache2. Then, I get an error that Mongo is not installed, due to the following line of code:

if (!extension_loaded('mongo')) die("MongoDB is not installed!");

phpinfo() indeed shows Mongo not being installed. I have created a php.ini file for apache using:

cp php.ini.default php.ini

and added the following line to the end of the file:

extension="/usr/local/opt/php56-mongo/mongo.so"

After restarting Apache, it still doesn't seem to load. I tried creating a copy of mongo.so in the same directory and give _www ownership (thought that may be the case), but still didn't work.

Strangely, the system tells me I have mail, which was sent from my Macbook to my Macbook, saying the following:

PHP Warning: PHP Startup: mongo: Unable to initialize module Module compiled with module API=20131226 PHP compiled with module API=20121212 These options need to match in Unknown on line 0

Any help on how to get the extension to load on Apache would be appreciated!......

1
Indeed, thanks, I faced the similar issue and I have to provide the correct path for mongodb setting for extension. It's at that location the same as you provided.haxpor

1 Answers

0
votes

Looks like I am running PHP version 5.5 and I did, per php.net's instructions

brew install php56-mongo

Apparently, I've missed that you must change this line based on the version installed. Therefore, after changing it to :

brew install php55-mongo

and following the brew instructions on how to remove the other versions installed (explanation on how to do that appears after you type in this command) - the new version has been installed.

Afterwards, I updated the /etc/php.ini to point to the right directory (which is different than the previous installation) - and it works!