the requested PHP extension mongo is missing from your system.

Got this error when trying to add the mongodb stuff your php project – specially using composer then here is how to solve it.

The first thing is you have to add the mongodb driver to php.

You might need PEAR on your system. Adding pear to your system is relatively easy and google can help on that.

Then do the following on your terminal

sudo pecl install mongo
pecl install mongo

The last lines of successful installation would tell where the installation has occurred and some more important information.

Now you need to add the mongo.so to the php.ini

if you don’t know where you have php.ini run (on ubuntu)

locate php.ini

then run

echo "extension=mongo.so" >> path-to-php.ini

Installing PEAR in Mac OSX

It looks the days of PEAR are somehow covered by the era of composer. But, still there might be things we will depend on PEAR, hence we have to install it.

Are you on Mac OSX and wants to install PEAR.. follow these simple steps and you will nail it

1. download the phar file from go-pear.phar

curl -O http://pear.php.net/go-pear.phar

2. Then run the phar file

sudo php go-pear.phar

In some cases, you might want to run it with -d detect_unicode=0 option
3. You will be provided with option that would look like the following:

1. Installation base ($prefix)                   : /Users/gullele/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /Users/gullele/pear/bin
 5. PHP code directory ($php_dir)                 : /Users/gullele/pear/share/pear
 6. Documentation directory                       : /Users/gullele/pear/docs
 7. Data directory                                : /Users/gullele/pear/data
 8. User-modifiable configuration files directory : /Users/gullele/pear/cfg
 9. Public Web Files directory                    : /Users/gullele/pear/www
10. Tests directory                               : /Users/gullele/pear/tests
11. Name of configuration file                    : /Users/gullele/.pearrc

Select 1 and enter where you would want to put the installation. In my case, I put it to the common installation directory /usr/local/pear

4. After that, you will have this options to choose:

1. Installation base ($prefix)                   : /usr/local/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/local/pear/bin
 5. PHP code directory ($php_dir)                 : /usr/local/pear/share/pear
 6. Documentation directory                       : /usr/local/pear/docs
 7. Data directory                                : /usr/local/pear/data
 8. User-modifiable configuration files directory : /usr/local/pear/cfg
 9. Public Web Files directory                    : /usr/local/pear/www
10. Tests directory                               : /usr/local/pear/tests
11. Name of configuration file                    : /Users/gullele/.pearrc

Ideally, you can put the binaries anywhere you want but you would have to add it to the PATH to be able to access it from anywhere. But if you put it inside /user/local/bin that would automatically be taken care of – do that and that would pretty much take you to the end of pear installation.

Happey PEARing