Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB and php in Ubuntu 11.04

I have install php and then mongodb using aptitude. I wrote following program:

   <?php

$m = new Mongo();

$db = $m->selectDB("Employees");

?>

and i got following error

PHP Fatal error: Class 'Mongo' not found in /var/www/test.php on line 4

I saw my php version it is:

PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May 2 2011 23:18:30)

Can anybody tell me why this problem is coming?

like image 526
hectk Avatar asked Jul 03 '11 16:07

hectk


People also ask

Can I connect PHP with MongoDB?

You can add the driver to your application to work with MongoDB in PHP. The MongoDB PHP Driver consists of the two following components: The extension , which provides a low-level API and mainly serves to integrate libmongoc and libbson with PHP.

How do you check MongoDB is installed or not in Ubuntu?

MongoDB installs as a systemd service, which means that you can manage it using standard systemd commands alongside all other sytem services in Ubuntu. To verify the status of the service, type: sudo systemctl status mongodb.


3 Answers

The PHP MongoDB is obviously not installed.

See MongoDB

like image 103
Andreas Jung Avatar answered Sep 22 '22 05:09

Andreas Jung


You have not installed MongoDB PHP driver please see this link http://www.php.net/manual/en/mongo.installation.php

Install MongoDB PHP Driver

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

Open your php.ini file and add to it:

extension=mongo.so
like image 42
Nanhe Kumar Avatar answered Sep 26 '22 05:09

Nanhe Kumar


Make sure you have apache2 and PHP5+ installed in your server:

sudo apt-get install apache2 php5 libapache2-mod-php5

Install some dependencies for the driver:

sudo apt-get install php-pear php5-dev

And install it: sudo pecl install mongo

Now, let's hack that php.ini too, located at /etc/php5/apache2/ path. Do that by adding mongo.so extension somewhere after the extensions part:

sudo vim /etc/php5/apache2/php.ini
Add : extension = mongo.so

Then restart apache server :

sudo service apache2 restart
like image 20
Mahbub Tito Avatar answered Sep 24 '22 05:09

Mahbub Tito