PHP: Mongo client not found

3

I've installed XAMPP on my MacBook. PHP and MySQL are working fine, so I followed it up with mongo. I did the following:

  • brew install mongo (success)
  • brew install autoconf (success)
  • sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo (success)

So far so good. I added the complete mongo.so path to the very end of `/etc/php.ini like so:

[mongo]
extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/mongo.so

The Problem:

Typing in php --version, however, returns the following:

PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20121212
PHP compiled with module API=20100525
These options need to match in Unknown on line 0
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)

What I Tried:

I managed to get rid of that error above (notice: get rid), by updating OS X's PHP via the following: curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5

I then added the following lines to .bash_profile: export PATH=~/bin:/usr/local/php5/bin:$PATH

php -m now lists mongo as one of the modules, and it no longer produces the above error.

However, phpinfo() does NOT have mongo, and running my webpage using mongo client gives me the following error:

FatalErrorException Class 'MongoClient' not found

So, I repeated the following: sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo

And now it's telling me that my mongo is up to date:

pecl/mongo is already installed and is the same as the released version 1.5.5

Additional info:

  • PHP version: PHP 5.5.14 (cli) (built: Jun 28 2014 10:29:43)
  • Mongo version: MongoDB shell version: 2.6.3
  • Mongo client: 1.5.5

zack_falcon

Posted 2014-08-06T06:47:08.617

Reputation: 903

Answers

4

Did you type php --version or /Applications/XAMPP/xamppfiles/bin/php --version? And to which php.ini did you add that line? To /etc/php.ini or to /Applications/XAMPP/xamppfiles/etc/php.ini?

The first path always references OS-X default PHP (which is PHP5.4), the later references XAMPPs PHP (which is PHP5.5 and has a different API then PHP5.4).

So I assume that you compiled the module for PHP5.5 (XAMPP) and have added it to PHP5.4 (OS-X). That can't work at all! You'l have to add the mongo so-Path to the end of the correct php.ini-file which in your case is the one for XAMPP which (if I recall corerctly) is located at /Applications/XAMPP/xamppfiles/lib/php.ini

heiglandreas

Posted 2014-08-06T06:47:08.617

Reputation: 1 153

I found it in /Applications/XAMPP/xamppfiles/etc/. That did it. Thanks! – zack_falcon – 2014-08-07T07:49:49.370

thanks for the info. I did out of my head and wasn't sure about lib or etc.... I've edited the answer to show the correct path! – heiglandreas – 2014-08-07T10:34:04.817

0

I had a problem with this for days. It worked out being the XAMPP\etc\php.ini. I added /usr/local/php5-5.6.25-20160831-101628/lib/php/extensions/no-debug-non-zts-20131226/mongo.so and it worked fine. To find where the mongo.so files are in Terminal enter locate mongo.so

Jase Moorcroft

Posted 2014-08-06T06:47:08.617

Reputation: 1