...">

PHP Fatal error: class "MongoClient" not found

I have a site using Apache, which is just the following code:

<?php $m = new MongoClient(); ?> 

and when I try to access it, I get an error in error.log

 `PHP Fatal Error: Class 'MongoClient' not found` 

Below are the settings, which may be incorrect, but I do not think so.

php -i | grep 'Configuration' php -i | grep 'Configuration' => Configuration File (php.ini) Path => /etc/php5/cli | Loaded Configuration File => /etc/php5/cli/php.ini Configuration File (php.ini) Path => /etc/php5/cli | Loaded Configuration File => /etc/php5/cli/php.ini

grep 'mongo' /etc/php5/cli/php.ini => extension=mongo.so

php -i | grep 'extension' php -i | grep 'extension' => extension_dir => /usr/lib/php5/20121212 => /usr/lib/php5/20121212

ls /usr/lib/php5/20121212/ | grep 'mongo.so' ls /usr/lib/php5/20121212/ | grep 'mongo.so' => mongo.so

I was unable to find anything to suggest that I install it incorrectly or incorrectly configure it. I installed it in the last two hours using pecl and pear ( sudo pear install -f pecl/mongo and sudo pecl install mongo )

I restarted my Apache and even my computer several times.

So why am I getting the Class 'MongoClient' not found error?

I'm on Ubuntu. PHP version 5.5.

Edit: I just discovered that MongoClient is valid when I run php interactively. Perhaps this is due to a user / user installation problem?

+6
source share
2 answers

The problem was that I used php -i | grep 'Configuration' php -i | grep 'Configuration' to search for the .ini file. This will result in /etc/php5/cli/php.ini . Looking back, this should have been an obvious fake: cli means the command line interface, mainly for the interpreter. I needed the ini file that Apache used.

Unfortunately, a great way to do this was not possible, since I could not log into the www-data user, but I created a file with the code

 <?php phpinfo(); ?> 

and it showed that the location of the .ini file was actually /etc/php5/apache2/php.ini .

As soon as I updated this ini file with extension=mongo.so , the module was loaded at startup, so I restarted and everything works now.

+5
source

I did this using the following sequence

 sudo apt-get install mongodb sudo service mongodb start mongo sudo pecl install mongo cd /build/buildd/php5-5.5.9+dfsg/pear-build-download sudo tar zxvf mongo-1.6.8.tgz cd mongo-1.6.8 sudo phpize cd ./configure sudo make install sudo gedit /etc/php5/apache2/php.ini add extension=mongo.ini inphp.ini sudo gedit/etc/php5/apache2/conf.d/mongodb.ini add extension=mongo.so sudo service apache2 restart 

and using the following URL

http://www.w3resource.com/mongodb/install-php-driver.php

+1
source

Source: https://habr.com/ru/post/982018/


All Articles