1

On my Ubuntu 12.04 installation I install PHP5 (5.5) from the ondej package. Everything works ok with the PHP, Apache and MySQL, I also successfully install Mongo daemom and Mongo client. But then PHP cannot locate the MongoDB driver in pear.

I have followed all the steps explained in the documentation I have added the extension to the php.ini file in the CLI folder restarted the server updated everything and restart the server again.

I have been stuck on this issue quite long time now. Where should I look in. My Ubuntu is also running on a virtual machine I have tried both on VMWare and VirtualBox (not that this has anything to do as far as I know).

Thanks

P.S. There are two similar issues here but they did not help me to solve my problem.

1
  • Check your php info and make sure mongodb section is there. Also check your server error log it should show up any errors while trying to load any extension from phpini Commented Mar 17, 2014 at 8:09

3 Answers 3

2
+150

I can give you my build recipe from a fresh 12.04 installation. Fresh being simply running through the configuration and only selecting the "SSH server" option at the end for convenience.

MongoDB installation is optional, so if you want this on a different server then skip. But the general instructions come from:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

All commands split up and not automated so you can see the steps:

sudo 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
sudo apt-get install software-properties-common
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
sudo apt-get install mongodb-10gen
sudo apt-get install build-essential
sudo apt-get install php5-dev
sudo apt-get install libcurl4-openssl-dev
sudo pecl install mongo

Lots of compiler output. Ending with success and asking to mofidy php.ini

Edit the CLI settings. And do the same for the apache config as well

sudo vi /etc/php5/cli/php.ini
sudo vi /etc/php5/apache2/php.ini

Personal preference, after the comments on 'Dynamic Extensions'

extension=mongo.so

Test that usage and connection does not throw an error. Create test.php:

<?php

    $m = new MongoClient('mongodb://localhost/',
        array('connectTimeoutMS'=> 500, 'socketTimeoutMS' => 500 ));

?>

And run from command line:

php test.php

No errors. Then you are all set up.

$ php -v
PHP 5.5.3-1ubuntu2.1 (cli) (built: Dec 12 2013 04:24:35)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the recipe which I followed before, but it still cannot find the driver. I tried with the current version of PHP from the apt-get 5.3.something and I had to add the mongo.ini in the mods-available directory for the PHP to find the driver and it did. However with the new version of PHP this trick does not work.
@HristoPetev The point is I followed these steps installing on a fresh VM and the driver is accessible to me. So if you start again and do the same then you will get the same result.
I followed the instruction on a new VM from scratch and the driver is still inaccessible. I tried this 3 times.
@HristoPetev Are you absolutely sure you have followed every step? I can equally say that this is reproducible as working. Are you possibly trying to access this from something other than the CLI? Such as in your application? Of course those are separate settings and you need to edit those as well.
@HristoPetev Glad to help. Don't forget to award the bounty. Be a shame for that to go to waste :)
|
2

Just in case here are my steps for php and mongo installation which I use on amazon:

sudo -i
add-apt-repository ppa:ondrej/php5
apt-get update && apt-get upgrade && apt-get install php5

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 install mongodb-10gen

apt-get install php-pear php5-dev
pecl install mongo

nano /etc/php5/apache2/php.ini

and change

error_reporting = E_ALL
display_errors = On

and add: extension=mongo.so

service apache2 restart

This will install you latest PHP, mongo, and latest mongodriver.

Comments

0

Install MongoDB PHP Driver:

sudo apt-get install php5-dev php5-cli php-pear
sudo pecl install mongo

Install php5-mongo Pacakge:

sudo apt-get install php5-mongo

Open your php.ini file and add to it:

extension=mongo.so

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.