marc0
240
1
Lumen

Command in Lumen is not connecting with the AWS RDS

Posted 3 months ago by marc0

I have a Lumen 5.7 application in Elastic Beanstalk with PHP 7.2, there are several endpoints that are working correctly, get and insert data in the RDS. But a Lumen command (that i created) is tryng to connect to localhost, ignoring the environment configuration. I execute this command via ssh.

I received this error:

[2019-03-29 18:37:01] production.ERROR: PDOException: SQLSTATE[HY000] [2002] Connection refused in /var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
Stack trace:
#0 /var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(27): PDO->__construct('mysql:host=127....', 'forge', '', Array)
#1 /var/app/current/vendor/illuminate/database/Connectors/Connector.php(67): Doctrine\DBAL\Driver\PDOConnection->__construct('mysql:host=127....', 'forge', '', Array)
#2 /var/app/current/vendor/illuminate/database/Connectors/Connector.php(46): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=127....', 'forge', '', Array)
#3 /var/app/current/vendor/illuminate/database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=127....', Array, Array)

It is trying to connect to 127.0.0.1 with the user forge. There is not a .env file in the server. Locally the command works correctly.

I've added the config/database.php file with the next code

return [
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
        ]
    ],

    'migrations' => 'migrations',

];

And I get this error now:

production.ERROR: InvalidArgumentException: Database hosts array is empty. in /var/app/current/vendor/illuminate/database/Connectors/ConnectionFactory.php:203

I deployed again and I received this error now:

[2019-03-30 01:12:53] local.ERROR: PDOException: SQLSTATE[HY000] [1045] Access denied for user 'user'@'xx.xx.xx.xx' (using password: YES) in /var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
Stack trace:
#0 /var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(27): PDO->__construct('mysql:host=dev-...', 'user', 'mypass...', Array)
#1 /var/app/current/vendor/illuminate/database/Connectors/Connector.php(67): Doctrine\DBAL\Driver\PDOConnection->__construct('mysql:host=dev-...', 'user', 'mypass...', Array)
#2 /var/app/current/vendor/illuminate/database/Connectors/Connector.php(46): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=dev-...', 'user', 'mypass...', Array)
#3 /var/app/current/vendor/illuminate/database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=dev-...', Array, Array)
#4 /var/app/current/vendor/illuminate/database/Connectors/ConnectionFactory.php(182): Illuminate\Database\Connectors\MySqlConnector->connect(Array)

Connection data is correct, but the user appears with the server ip [email protected]and I don't know if this is correct.

Please sign in or create an account to participate in this conversation.