4
votes

I entered the following commands on my command terminal in order to use the 'MongoClient' with PHP on XAMPP on my Macbook Pro:

  • brew install wget
  • brew install autoconf
  • sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo
  • Added extension=mongo.so to php.ini /Applications/XAMPP/xamppfiles/etc
  • Restarted Apache

However, I have had no luck. I keep getting this error: Fatal error: Class 'MongoClient' not found in /Applications/XAMPP/xamppfiles/htdocs/xampp/index.php on line 5

I'm getting kind of frustrated because I don't really know what else to try. Any advice?

1
Have you done this: sudo apt-get install php5-dev php5-cli php-pear -y sudo pecl install mongoSalvador Dali
@SalvadorDali I didn't use that, but I just tried to and it said "sudo: apt-get" command not found.Vimzy
forgot that you are using mac. Have you followed installation for a php driver for mac, outlined here: php.net/manual/en/mongo.installation.php?Salvador Dali
@SalvadorDali When I do: sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo I get: "pecl/mongo is already installed and is the same as the released version 1.6.8 install failed"Vimzy
CURRENT STATUS: When running "brew install php56-mongo" I get "No available formula for php56-mongo"Vimzy

1 Answers

5
votes

You need to start mongod

brew update

brew install mongodb

mkdir -p /data/db

mongod --dbpath /data/db

Before running mongod for the first time, ensure that the user account running mongod has read and write permissions for the /data/db directory.

Install MongoDB PHP driver

brew install php56-mongo

OR

sudo pecl install mongo