moadmin fails to find mongodb extension - php

moadmin.php reports it can't access mongodb and that I must install the mongo extension for php. Moadmin version is 1.1.5 and github reports the latest edit was in 2017. The extension was installed on my ubuntu 18.04 lts server as instructed in php.net with the command:
pecl install mongo
However, the extension has been installed and phpinfo confirms it. I have also tested the extension with the code provided by php.net.
<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>
This test code resides in the same folder as moadmin.php and the Vork Enterprise Framework has likewise been installed in that folder.
I have also confirmed mongo is running on the server and can be accessed via
mongo
and reports
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
I've also tried connecting with dbKoda but it reports
Error: All configured authentication methods failed
even though its URI is
mongodb://127.0.0.1:27017
Not sure where to go or what to try from here to get a working connection to mongo from my win10 machine. As I indicated the test code works in the browser on the win10 machine but not moadmin nor dbKoda.
Suggestions please?

Related

phpinfo() and pecl search mongo shows different version of mongodb

I have installed MongoDB on my local pc referring below site
http://linuxforever.info/2017/04/13/how-to-install-mongodb-3-4-in-linux-mint-18-ubuntu-16-04/
I made a simple demo of MongoDB and when I ran the project I got an error like
Fatal error: Call to undefined method
MongoDB\Driver\WriteConcern::isDefault()
I have checked MongoDB version on both side (phpinfo.php and terminal) it's different.
Terminal => pecl search mongo command
Matched packages, channel pecl.php.net:
Package Stable/(Latest) Local
mongo 1.6.16 (stable) MongoDB database driver
mongodb 1.4.3 (stable) 1.4.3 MongoDB driver for PHP
Phpinfo =>
MongoDB extension version 1.2.9
MongoDB extension stability stable
libbson bundled version 1.5.5
libmongoc bundled version 1.5.5
Please help me to clear this issue.
Thanks in advance
<?php
require_once './vendor/autoload.php';
$con = new MongoDB\Client("mongodb://localhost:27017");
// Creating Database
$db = $con->yourdbname;
// Creating Document
$collection = $db->employee;
// Insering Record
$collection->insertOne( [ 'name' =>'Peter', 'email' =>'peter#abc.com'] );
// Fetching Record
$record = $collection->find( [ 'name' =>'Peter'] );
foreach ($record as $employe) {
echo $employe['name'], ': ', $employe['email']."<br>";
}
?>
please check this screen short
Try Installing using following command :
pecl install mongodb
Add extension to your php.ini file at the end
extension = mongodb.so
Restert your php and apache server
Use composer to load mongo db packages
composer require mongodb/mongodb
Run following code after above process
<?php
require 'vendor/autoload.php';
// Creating Connection
$con = new MongoDB\Client("mongodb://localhost:27017");
// Creating Database
$db = $con->yourdbname;
// Creating Document
$collection = $db->employee;
// Insering Record
$collection->insertOne( [ 'name' =>'Peter', 'email' =>'peter#abc.com' ] );
// Fetching Record
$record = $collection->find( [ 'name' =>'Peter'] );
foreach ($record as $employe) {
echo $employe['name'], ': ', $employe['email']."<br>";
}
MongoDB\Driver\WriteConcern::isDefault() was introduced in ext-mongodb 1.3
You have MongoDB extension version 1.2.9 as you shared output of phpinfo().
You need to update the extension.
UPDATE
You can download latest extension from following link
https://pecl.php.net/package/mongodb
Linux Mint is Debian based and you can install following package on it to upgrade
https://ubuntu.pkgs.org/18.04/ubuntu-universe-amd64/php-mongodb_1.3.4-1build1_amd64.deb.html
I had a similar issue which I solved after several hours. Hopefully this saves others some time. I'm on macOS Sierra.
Background
I ran sudo pecl install mongodb to update mongo driver. I didn't need to add the extension to php.ini because it was there from an older version.
PHP refused to recognize the updated mongo driver. I would also receive the Fatal error: Call to undefined ... isDefault() error when trying to execute queries.
The fix
Step 1
Find the full path of the new mongodb driver extension.
There are a few ways to do this.
Updating the driver (i.e. sudo pecl install mongodb) will output something like:
Installing
'/usr/local/Cellar/php71/7.1.2_13/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so'
Alternatively, you could search for it: find / -name "mongodb.so" on Mac or Linux.
Step 2
Locate your php.ini file.
Again there are a few different ways.
Echoing phpinfo() in php will tell you where it is.
Alternatively you could run find / -name php.ini.
Mine was located at /usr/local/etc/php/7.1/php.ini
Step 3
Edit your php.ini file, and replace
extension="mongodb.so"
with the path to the new extension:
extension="/usr/local/Cellar/php71/7.1.2_13/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so"
Step 4
Save and retry your query.
More info
In my case, php.ini was actually including the mongo extension from /usr/local/etc/php/7.1/conf.d/ext-mongodb.ini, so this was the file that I edited. However I successfully tested both solutions.

php7 mongodb authentication fails

I have installed a php7 + mongodb 3.2 in an ubuntu stack:
pecl install mongodb (this is the new driver for > 5.99.99)
I'm also using the last php package mongodb/mongodb as wrapper.
but I have problems to authenticate the user.
new \MongoDB\Client('mongodb://root:123456#somehost:27017');
it fails due the authentication mechanism, the driver is trying to authenticate as MONGODB-CR (deprecated in > 3.0) instead of SCRAM-SHA-1
Of course, the authentication works well with a shell mongo client:
mongo someip:27017/admin -u root -p "123456"
The question is, how can I specify the authentication mechanism in the php driver? (The \MongoDB\Client constructor accepts some array $driverOptions = []), is there any option to specify it?
Thanks!
Make sure that you are using the latest driver. As the new default should have been SCRAM-SHA-1.
I ran a test under environment: php7, ubuntu14, MongoDB v3.2.x, mongo-php-library =^1.0.0 and mongodb php driver v1.1.5. Which works as expected.
require_once __DIR__ . "/vendor/autoload.php";
$client = new MongoDB\Client("mongodb://user:pwd#host:port/admin");
$collection = $client->selectCollection("databaseName", "collection");
$cursor = $collection->find();
foreach ($cursor as $document) { var_dump($document); }
I've also tested authMechanism option in the URI, for example:
$client = new MongoDB\Client("mongodb://user:pwd#host:port/admin?authMechanism=SCRAM-SHA-1");
Which also works, although you shouldn't need to specify SCRAM-SHA-1 if you are using the new PHP driver. If you run php --ri mongodb you should be seeing something similar to (for v1.1.5):
mongodb
mongodb support => enabled
mongodb version => 1.1.5
mongodb stability => stable
libmongoc version => 1.3.3
libbson version => 1.3.3

Mac OS X MongoDB and MONGO PHP DRIVER

i try to install MongoDB and Mongo PHP Driver for 5.6.x for MAMP PRO , but i finishing installation (also i add extension on php.ini) but still doesn't work. Any one help me ?
it would be useful if you could give more information about versions (MAMPP version, MongoDB server version, Mongo driver version...).
However the most common problem with Mongo and php is that there are two different drivers, both can be installed through PECL.
mongo-php : Legacy driver, not recommended anymore.
sudo pecl install mongo
Add to php.ini -> extension=mongo.so
mongodb-php : New driver, recommended.
sudo pecl install mongodb
Add to php.ini -> extension=mongodb.so
While mongo-driver works with PHP versions < 7.0 mongodb driver works with PHP versions > 5.5. But some libraries are still using old mongo driver (i.e.doctrine) and could need an adapter if you want to work with the new driver.
Old driver repo: https://github.com/mongodb/mongo-php-driver-legacy
New driver repo: https://github.com/mongodb/mongo-php-library
To be sure which driver is working in your system, you can perform this easy test. Create two PHP scripts with the following initialization:
If this works then you have old driver installed
$connection = new MongoClient({here your conn data})
If this works then you have the new driver installed
$connection = new MongoDB\Driver\Manager({here your conn data})
Hope this will be useful for any user with the same problem on any platform.
(Please note the extension for windows user will be .dll instead of .so)

Unable to connect mongo db server from php driver

I have installed the mongo db server and i have run the server from the command prompt administrator up to installing the mongo db server and running the mongo db server was fine.
when i have to install the mongo db php driver
the specifications mentioned by the php mongo db server i have done...here i am placing my details what needs
PHP Version 5.6.12
Compiler MSVC11 (Visual C++ 2012)
Zend Extension Build API220131226,TS,VC11
PHP Extension Build API20131226,TS,VC11
i have choosen the php_mongo-1.6.8-5.6-vc11-nts and renamed it as php_mongo and placed in php extension folder
and in php.ini file written extension=php_mongo.dll after that i have restarted my xampp server
even though it is giving the following error
Fatal error: Class 'Mongo' not found in C:\xampp\htdocs\test\test.php on line 3
please suggest anyone
thanks in advance

MongoDB on Amazon EC2 - Configuring Mongo Client for Php

I am pretty new to Amazon EC2.
I followed the instructions given in mongodb official site for installing mongodb on Amazon Linux. I have a Yii-2(basic) project to host on my amazon Linux server. mongoDB is already installed in the and even I Imported some dumps over there. But when i run the project
Class 'MongoClient' not found
How can I configure mongodb on amazone linux?
(now when i do sudo service mongod restart it is showing FAILED)
I installed mongodb using yum.
PHP version 5.6
Amazon Linux
these are my configuration. I am sure I am using latest versions since it is a fresh installation. Please help me out. Thanks in advance!
From the error message it seems that you haven't installed the PHP Mongo Driver in your server.
To check if you have it, try a php_info() and check if the entry "mongo" is present
If it's not present install it using the instructions found in the link above, or check here

Categories