MongoDB and php in Ubuntu 11.04

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

<?php $m = new Mongo(); $db = $m->selectDB("Employees"); ?> 

and I got the following error

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

I saw my php version:

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

Can someone tell me why this problem is occurring?

+7
source share
4 answers

PHP MongoDB is obviously not installed.

See MongoDB

+6
source

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

Install PHP MongoDB Driver

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

Open the php.ini file and add to it:

 extension=mongo.so 
+4
source

Make sure apache2 and PHP5 + are installed on 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 this php.ini too located in / etc / php 5 / apache2 / path. Do this by adding the mongo.so extension somewhere after the extension part:

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

Then restart the apache server:

 sudo service apache2 restart 
+3
source

Install the 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 the php.ini file and add to it:

extension = mongo.so

0
source

All Articles