0
votes

I am using Ubuntu 12.04, PHP 5.5.13 (cli) and Apache/2.4.10. I installed Mongodb 2.6.4. It's working fine. Then i installed PHP-MongoDB driver. It got installed but is not showing in phpinfo(). When i execute php file with mongodb, i get the following error:

 PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/mongo.so' - /usr/lib/php5/20121212/mongo.so: cannot open shared object file: No such file   or directory in Unknown on line 0
 [Sun Aug 24 11:48:39.403845 2014] [:error] [pid 3008] [client 127.0.0.1:58857] PHP Fatal error:  Class 'MongoClient' not found in /var/www/PHP/php-mongo/testingmongodb.php on line 3, referer: http://localhost/PHP/php-mongo/

I installed PHP Mongodb driver as follows:

 sudo pecl install mongo

There are two php.ini so i added

 extension=mongo.so

in both php.ini

 /etc/php.ini
 /etc/php5/apache2/php.ini

Then, restarted apache2

I also tried manual way.

unzip php_mongo-1.5.1.zip
cd mongodb-php-driver
phpize
./configure
sudo make install

While excuting phpize, i got the following error:

 Cannot find config.m4. 
 Make sure that you run '/usr/bin/phpize' in the top level source directory of the module

I also create a file /etc/php5/conf.d/mongo.ini and added "extension=mongo.so" but, still nothing is happening. I can't figure it out what's happening. Please help me in this.

1
Did you get any errors installing via pecl? In your first log messages it looks like the mongo.so extension wasn't installed in the expected directory ("/usr/lib/php5/20121212/"). When you tried the manual way, it seems like you're missing the PHP source. Have you tried sudo apt-get install php5-dev php5-cli php-pear before installing (as per the MongoDB manual). - Stennie

1 Answers

0
votes

If you use use CLI command, you may need to add Mongo driver to the cli specific php.ini:

echo "extension=mongo.so" >> /etc/php5/cli/php.ini

For info, here is how I installed Mongo and mongo driver (according to the doc):

sudo -s
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
apt-get update
apt-get -y install mongodb-org
grep -q "extension=mongo.so" /etc/php5/apache2/php.ini || echo "extension=mongo.so" >> /etc/php5/apache2/php.ini
grep -q "extension=mongo.so" /etc/php5/cli/php.ini || echo "extension=mongo.so" >> /etc/php5/cli/php.ini && pecl install mongo
service apache2 restart