Asked  1 Year ago    Answers:  5   Viewed   19 times

In our Laravel 5.2 app, we have a DB setup running on AWS, using multiple read servers (and multiple DB connections).

At night, we changed the DNS resolvers for all web servers to the Google DNS ( and Then, the servers started spitting these:

PDOException: Exception 'PDOException' with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known' in /home/forge/

The code at Connector.php:55 is simply the PDO constructor:

public function createConnection($dsn, array $config, array $options)
    $username = Arr::get($config, 'username');

    $password = Arr::get($config, 'password');

    try {
        $pdo = new PDO($dsn, $username, $password, $options); // <== THIS ONE
    } catch (Exception $e) {
        $pdo = $this->tryAgainIfCausedByLostConnection(
            $e, $dsn, $username, $password, $options

        return $pdo;

The .env config for the AWS (with sesnsitive parts changed):

So, it seems like PHP's PDO suddenly cannot resolve the DB_HOST name.

Note, that we cannot use an IP for the DB_HOST, as the hostname (on the AWS side) maps to 3 different database READ servers.

Also, before we changed the resolvers, all was working fine.

Anyone has any idea what might be causing the PDO error, or how to resolve it?



This is a bug in libc, according to:

php_network_getaddresses: getaddrinfo failed: Name or service not known ubuntu

Saturday, May 29, 2021


Your DSN format is wrong, it shouldn't have those quotes in there. This is the right format

 //$con=new PDO($dsn, $user, $password);
 $con=new PDO('mysql:dbname=testdb;host=','root',''); 

See Manual

Thursday, April 1, 2021

If you are running SELinux on your centos EC2, try switching off SELinux and test your application again. If it's SELinux that's causing this problem, it might well be because of the policy for external connection to database. You should switch SELinux back ON and enable the policy with this command.

sudo setsebool -P httpd_can_network_connect_db=1
Friday, August 13, 2021

To install nodejs using yum (assuming you're using the default Amazon Linux)

curl --silent --location | sudo bash -
yum -y install nodejs

Now to execute this on your instances, you need to add the required commands to a config file inside the .ebextensions dir, something like: .ebextensions/01_install_dependencies.config

File contents:

    command: curl --silent --location | sudo bash -
    command: yum -y install nodejs
Wednesday, September 29, 2021

unless you need a dedicated instance just for your cakephp application you may be better off using a host that provides a full lamp hosting stack on a shared server.

with aws you would need to create an instance, configure that instance, eg install mysql if that is what you want, etc.

then you pay-per-hour while it is running, so for a full year it would be like 24*365*12c = $1050 approx. (you will need to check the exact rates for what you want)

Saturday, October 16, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :