2

just set up a fresh development ubuntu 13.04 server with nginx, php-fpm, and mongodb. The following line of code kills all of my scripts that were running great on a production ubuntu 12.10 server

$m = new MongoClient("mongodb://user:pass@/tmp/mongodb-27017.sock/database");

error

Warning: MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/app/php/db.php on line 4

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: /tmp/mongodb-27017.sock:0: php_network_getaddresses: getaddrinfo failed: Name or service not known' in /var/www/app/php/db.php:4 Stack trace:

0 /var/www/app/php/db.php(4): MongoClient->__construct('mongodb://app...')

1 /var/www/app/admin/loggedin.php(3): require('/var/www/app...')

2 /var/www/app/admin/index.php(1): require('/var/www/app...')

3 {main} thrown in /var/www/app/php/db.php on line 4

I've been toying with this for a day and half and can't figure it out. It works when I connect to localhost but I'd really prefer sockets. any ideas?

2 Answers 2

0

The PHP driver does not support passing in the credentials as part of the URI when connecting over Unix Domain Sockets.

You need to pass in the username and password in the $options array (2nd argument).

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, thats not true. We do support that - you are probably running into a bug PHP-846 that was fixed in 1.4.1.
0

Ubuntu 14.04, Php 5.59, MongoDB shell version: 2.4.9

I got mine to work by passing the following:

I had to change my connection from $m = new Mongo(); // connect to $m = new Mongo("mongodb://127.0.0.1"); // connect

For some reason it appears that the /etc/hosts file stopped being called localhost for 127.0.0.1 which was throwing off the default mongodb connector so I had to be explicit. Sigh.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.