How to update MongoDB PHP Driver 1.4.5 to latest version for PHP 5.5.9

2,492 views
Skip to first unread message

Sridhar Naguru

unread,
Sep 15, 2016, 1:02:23 PM9/15/16
to mongodb-user
Hi All,

We are developing mongodb application and  configured PHP and mongodb in AWS.
In my project , we are using mongodb version 3.2.4 in ubuntu 14.04 as Production server, mongodb version 2.4.9  in ubuntu 14.04 as other server,

And we configured PHP 5.5.9 and which contains php-mongodb version 1.4.5 and the OS is ubuntu 4.17;

In mongodb 2.4.9 server does not contain credentials. It can connect db  through PHP .
But In mongodb 3.2.4 server have credentials and when I tried to connect Authentication failed message shows.
But actually client was able to connect the production server through android application using node js.


If I want to update php-mongo driver for PHP 5.5.9 in ubuntu4.17, How caI proceed for that?

Could you please help me resolve the issue


Regards,
Sridhar.N



Jeremy Mikola

unread,
Sep 15, 2016, 2:30:28 PM9/15/16
to mongod...@googlegroups.com
On Thu, Sep 15, 2016 at 5:46 AM, Sridhar Naguru <sridhar...@gmail.com> wrote:
Hi All,

We are developing mongodb application and  configured PHP and mongodb in AWS.
In my project , we are using mongodb version 3.2.4 in ubuntu 14.04 as Production server, mongodb version 2.4.9  in ubuntu 14.04 as other server,

And we configured PHP 5.5.9 and which contains php-mongodb version 1.4.5 and the OS is ubuntu 4.17;

I expect you're using the legacy PHP driver ("mongo" extension). Note that this has been superseded by the "mongodb" extension, which has a new API.

That said, 1.4.5 is quite outdated even for just the legacy driver. The most recent release of the "mongo" extension is 1.6.14, so I would suggest upgrading first. If you look through the change logs since 1.4.5, there were several improvements in the 1.5.x and 1.6.x series to support new auth protocols.

Officially, only the newer "mongodb" extension supports all features of MongoDB 3.2. Versions 1.5.x and 1.6.x of the "mongo" extension only support MongoDB 2.6 and 3.0, respectively (see: this compatbility table). You should still be able to connect to a 3.2 server with the older driver versions; however, incompatible drivers may be missing things like command helper methods or updated protocols for features introduced in a later server version.
 

In mongodb 2.4.9 server does not contain credentials. It can connect db  through PHP .
But In mongodb 3.2.4 server have credentials and when I tried to connect Authentication failed message shows.
But actually client was able to connect the production server through android application using node js.

Please share code examples from each driver so we can compare. This should include the MongoClient URI strings and any additional options (the PHP drivers take options arrays in addition to a URI string) so we can compare. Feel free to redact any sensitive information as needed.

URI strings (supported by all drivers) are documented on in the MongoDB manual. For the legacy PHP driver, array options are documented in the manual page for MongoClient::__construct().

Message has been deleted

Sridhar Naguru

unread,
Sep 16, 2016, 3:54:50 AM9/16/16
to mongodb-user

Hi,
I ran sample code to test connection.

My sample code: test.php
<?php

$connection = new Mongo("mongodb://username:pass...@api.abcdef.com:27017/mydb?authSource=admin");
 $database = $connection->selectDB('mydb');
$collection  = $database->selectCollection('
mycol');
$result = $collection->find();

foreach($result as $data) {
echo "Email : ".$data['email']." / Name:  ".$data['name']." /Id:  ".$data['_id']."<br>";
}

?>

For eg:
http://<host>/test/test11.php
O/p:
Failed to connect to: api.abcdef.com:27017: Authentication failed on database 'admin' with username 'username': auth failed





Jeremy Mikola

unread,
Sep 16, 2016, 10:25:36 AM9/16/16
to mongod...@googlegroups.com


On Fri, Sep 16, 2016 at 3:24 AM, Sridhar Naguru <sridhar...@gmail.com> wrote:

My sample code: test.php

Quick aside: the Mongo class has been deprecated since version 1.3.0. Please use MongoClient instead. The only difference is that MongoClient defaults to an acknowledged write concern, which is generally advised over the old default of unacknowledged writes.

Do either your username or password include special characters (such as ":" or "@") or URI-encoded values (i.e. "%" followed by two numbers)? If so, you will need to specify them in the options array (second constructor argument). The legacy driver's URI parsing (defined here for version 1.4.5) is fairly primitive and does not handle URI-encoded values.

The new driver ("mongodb" extension), which uses our C driver internally, does handle URI encoding.

If specifying the username and password in the array options still does not work, it may be helpful to collect MongoLog output from a failed case. This will generate quite a bit of output, so you'd want to share it as a paste or GitHub gist instead of copying the entire thing into a mailing list reply.

MongoLog::setCallback() has some example code that you can use to create some logs of internal driver activity (this includes URI parsing as well as network activity).


Sridhar Naguru

unread,
Sep 17, 2016, 12:36:49 AM9/17/16
to mongod...@googlegroups.com
Hi,

I am connecting AWS through Win SCP tool and tried some commands to update, but it was taken more than 1 hour and then abort the connection.
Cmds:

sudo apt-get install -f php-pear php5-dev ( here abort the connection)

sudo pecl install mongo



What are the steps to update latest php-mongo driver in AWS ec2?

How can I update the driver?


Best Regards

Sridhar N



On Fri, Sep 16, 2016 at 7:54 PM, Jeremy Mikola <jmi...@mongodb.com> wrote:
On Fri, Sep 16, 2016 at 3:24 AM, Sridhar Naguru <sridhar...@gmail.com> wrote:

My sample code: test.php

$connection = new Mongo("mongodb://username:passwo...@api.abcdef.com:27017/mydb?authSource=admin");

Quick aside: the Mongo class has been deprecated since version 1.3.0. Please use MongoClient instead. The only difference is that MongoClient defaults to an acknowledged write concern, which is generally advised over the old default of unacknowledged writes.

Do either your username or password include special characters (such as ":" or "@") or URI-encoded values (i.e. "%" followed by two numbers)? If so, you will need to specify them in the options array (second constructor argument). The legacy driver's URI parsing (defined here for version 1.4.5) is fairly primitive and does not handle URI-encoded values.

The new driver ("mongodb" extension), which uses our C driver internally, does handle URI encoding.

If specifying the username and password in the array options still does not work, it may be helpful to collect MongoLog output from a failed case. This will generate quite a bit of output, so you'd want to share it as a paste or GitHub gist instead of copying the entire thing into a mailing list reply.

MongoLog::setCallback() has some example code that you can use to create some logs of internal driver activity (this includes URI parsing as well as network activity).


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CACypnJVJM_vptRR96wqByW0nB4OEb%2Brjm4yjvE-9oosMOHqtWA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Sridhar Naguru

unread,
Sep 17, 2016, 1:09:14 PM9/17/16
to mongod...@googlegroups.com

Hi,

I have updated php-mongo driver version 1.1.8 ( Ref: https://pecl.php.net/package/mongodb)

It needs to modify php.ini in /etc/php5/apache2/php.ini,

in php.ini file,need to add line as  extension=mongodb.so
then need to restart the apache server.It should be affected and display the version in mongodb module in phpinfo page.

And I found in /etc/mongodb.conf , both are in comments.

#noauth = true
#auth = true
 Here one should not be comment.(Need to remove #)

If I do like this , Will mongodb driver update properly?

Best Regards

Sridhar N

Jeremy Mikola

unread,
Sep 17, 2016, 3:12:21 PM9/17/16
to mongod...@googlegroups.com
On Sat, Sep 17, 2016 at 1:07 PM, Sridhar Naguru <sridhar...@gmail.com> wrote:

I am connecting AWS through Win SCP tool and tried some commands to update, but it was taken more than 1 hour and then abort the connection.
Cmds:

sudo apt-get install -f php-pear php5-dev ( here abort the connection)

sudo pecl install mongo


`sudo pecl upgrade mongo` should be sufficient for upgrading the driver version. I can't comment on why your connection was aborting during `apt-get install`.

For future reference, install instructions for the old and new driver are found on the following PHP.net pages:

I have updated php-mongo driver version 1.1.8 ( Ref: https://pecl.php.net/package/mongodb)

It needs to modify php.ini in /etc/php5/apache2/php.ini,

in php.ini file,need to add line as  extension=mongodb.so
then need to restart the apache server.It should be affected and display the version in mongodb module in phpinfo page.

The INI update sounds correct.

As I stated earlier, the mongodb and mongo extensions have different APIs, and migrating to the new driver will surely require changes to your application code. If you were able to use pecl to install the mongodb extension, I don't see why you wouldn't have been able to upgrade the mongo extension (as stated in your second to last post).

And I found in /etc/mongodb.conf , both are in comments.

#noauth = true
#auth = true
 Here one should not be comment.(Need to remove #)

If both options are commented, the default behavior is no authentication. Both options are documented here:

Note that MongoDB 2.6 introduced a YAML configuration format, which uses different option names from the original mongodb.conf format (documented here).

I'm also quite confused how this (disabled auth in your server configuration) relates to your earlier post about using authentication via the PHP and Node.js drivers.

If I do like this , Will mongodb driver update properly?

I don't see the relation between your server configuration and upgrading the driver.

Did you have any follow-up to my previous question on whether there were URI-encoded characters in the username and password?

Reply all
Reply to author
Forward
0 new messages