MongoConnectionException in local, not in remote - php

I am trying to connect to MongoDB from local (a Azure VM). I can connect when I try in my localhost workspace with the URL of the VM. But, when I try to connect in localhost there is a error:
At localhost:
$m = new Mongo("mongodb://xxx.cloudapp.net:27017");
At local VM:
$m = new Mongo("mongodb://localhost:27017");
I also try with: 127.0.0.1 and xxx.cloudapp.net.
This is the error:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: Permission denied' in /var/www/html/test.php:8 Stack trace: #0 /var/www/html/test.php(8): Mongo->__construct('mongodb://local...') #1 {main} thrown in /var/www/html/test.php on line 8

This is not a new issue. This is a regular issue, the problem is with the instalation.
Please check it out: http://www.php.net/manual/en/mongo.installation.php#mongo.installation.fedora
You have to run
$ /usr/sbin/setsebool -P httpd_can_network_connect 1 and then restart apache service to fix the problem.
Thank you all

Related

Fatal error: Uncaught exception 'MongoConnectionException' with message

I am testing the mongoDB in localhost and successfully installed the mongoDB in localhost. I have tried to connect the mongoDB using PHP in localhost.
It throws the error like 'Authentication failed'. It is successfully authenticated in cmd prompt.
Below is my code:
$username = 'testUser';
$password = 'testPassword';
$m = new MongoClient("mongodb://testUser:testPassword#localhost", array("db" => "testdb"));
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: No connection could be made because the target machine actively refused it. ' in E:\xampp\htdocs\xampp\test.php:3 Stack trace: #0 E:\xampp\htdocs\xampp\test.php(3): MongoClient->__construct('localhost:27017', Array) #1 {main} thrown in E:\xampp\htdocs\xampp\test.php on line 3
I have also changed the localhost to ip(127.0.0.1) address but no use. Thanks in advance

MAMP on Yosemite - connection error : SQLSTATE[HY000] [2002] No such file or directory

I know that I have seen this question before but have not seen an answer that has been able to fix the issue on my machine.
I'm relatively new to PHP and have no experience with Apache settings.
I am using the latest version of MAMP (not pro) with all the default settings on the latest version of OS X (10.3.3).
When I try to connect via PDO I receive the following error:
Unable to connect to the database server.exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/resources/config.php:7 Stack trace: #0 /Applications/MAMP/htdocs/resources/config.php(7): PDO->__construct('mysql:host=loca...', 'USERNAME', 'PASSWORD') #1 /Applications/MAMP/htdocs/WEBSITE/index.php(2): include_once('/Applications/M...') #2 {main}
The connection code is from Kevin Yank's Novice to Ninja book, modified to apply to my database, username, etc.
try
{
$pdo = new PDO('mysql:host=localhost;dbname=db', $DBUser,$DBPass);
}
catch (PDOException $e)
{
$error = 'Unable to connect to the database server.' . $e;
include 'error.html.php';
exit();
}
I have tried localhost and 127.0.0.1 and get the same error regardless.
I don't see anything in Console that could help but I may not be looking for the right thing.
Any help is appreciated. Thanks
try this command in mac
ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
This could happen if mysqld is not running (stuff happens). It could also happen if you have a configuration error.
For example, on my installation, i reproduce the error with this DSN :
mysql:unix_socket=/tmp/mysqle.sock;dbname=notifications;charset=utf8
the config calls for /tmp/mysql.sock
Check the config to see what method is configured (port or socket) and which (port or socket). If you have the wrong port or socket in your DSN, you will produce the same error report in the question.

php failed to connect to mongodb socket

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?
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).
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.

Question about PHP PDO INFORMIX ERROR

I have installed PDO_INFORMIX and CSDK already on CentOS5.6 32bits
and index.php have
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$db = new PDO("informix:host=172.30.179.81; service=5000;database=cms; EnableScrollableCursors=1", "myuser", "mypassword");
print("OK");
?>
but i still got this error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE=HY000, SQLDriverConnect: -11060 [Informix][Informix ODBC Driver]General error.' in /usr/local/apache/htdocs/index3.php:5 Stack trace: #0 /usr/local/apache/htdocs/index3.php(5): PDO->__construct('informix:host=1...', 'myuser', 'mypassword') #1 {main} thrown in /usr/local/apache/htdocs/index3.php on line 5
Have anyone know what it is ?
Thanks
Ouch! The standard technique for finding out more about errors is:
$ finderr -11060
-11060 General error.
An error occurred that has no specific SQL_STATE. In this case,
additional text is provided that identifies the source of the problem.
This IBM Informix CLI error code is the same as SQLSTATE value S1000.
$
That is not very helpful - to be polite about it.
There are spaces in the connect string; does removing them help at all?
Can you telnet to the host 172.30.179.81?
Can you telnet to the port (service) 5000 on the host?
Can you connect from this machine using any other Informix tool?
Can you connect from other machines using the same connect string?
In case of desparation, can you track down whether all the shared libraries are loading correctly?

"Lost connection to MySQL server" when trying to connect to remote MySQL server

I am using Zend Framework to develop my application and I try to connect to a remote MySQL database in my LAN.
The database connection settings in Zend is as follows:
[GENERAL]
db.adapter = PDO_MYSQL
db.params.host = 192.168.1.2
db.params.port = 3306
[LIVE:GENERAL]
db.params.username = root
db.params.password = **
db.params.dbname = djudd
[DEVELOPMENT:GENERAL]
db.params.username = root
db.params.password = **
db.params.dbname = stellarengine
I got the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111' in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php:129 Stack trace: #0 /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:host=192....', 'root', 'password', Array) #1 /usr/share/php/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect() #2 /usr/share/php/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect() #3 /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBEbny_c...', Array) #4 /usr/share/php/Zend/Db/Adapter/Pdo/Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE bny_c...') #5 /usr/share/php/Zend/Db/Table/Abstract.php(823): Zend_Db_Adapter_Pdo_Mysql->describeTable('bny_core_module...', NULL) #6 /usr/share/php/Zend/Db/Table/Abstract.php(866): Zend_Db_Table_Abstract->_setupMetadata() #7 /usr/share/php/Zend/Db/Table/Abstract. in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php on line 144
Please help me to resolve this problem.
Last time I had this type of error, I had to change my host from: 127.0.0.1 to 'localhost' and then it worked fine.
This might help: MySQL Forum: 'reading initial communication packet', system error: 111
I had the same problem, to solve it I changed the remote port in the tunnel configuration from 'localhost:3306' to '127.0.0.1:3306'.
In the target machine, localhost was resolving to ::1 but MariaDB was not listening IPv6 requests...
This error means you're connecting to the wrong server or the firewall blocked it or the server isn't running.
You'll need to contact the server administrator to confirm the correct details.
With most servers you'll use 127.0.0.1 but some use localhost while others (like media temple) will need a full domain name - for example internal-db.s421234.gridserver.com

Categories