简体   繁体   中英

mongo php driver extension loads in cli, not apache in OSX

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!......

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM