Lumen中的Command未与AWS RDS连接

时间:2019-03-29 19:23:09

标签: amazon-web-services lumen amazon-elastic-beanstalk

我在PHP 7.2的Elastic Beanstalk中有一个Lumen 5.7应用程序,有几个端点正常工作,在RDS中获取和插入数据。 但是Lumen命令(我创建的)试图连接到本地主机,而忽略了环境配置。 我通过ssh执行此命令。

我收到此错误:

[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)

它正在尝试使用伪造用户连接到127.0.0.1。 服务器中没有.env文件。 该命令在本地正常运行。 有人可以帮我吗?

编辑: 我用下面的代码添加了config / database.php文件

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',

];

现在我收到此错误:

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

编辑2 我再次部署,现在收到此错误:

[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)

连接数据正确,但是用户使用服务器IP user@ip.of.the.server出现,我不知道这是否正确。

1 个答案:

答案 0 :(得分:0)

密码包含一个“ $”字符。由于某种原因,Lumen将该字符之前的密码截断了。它已被删除,并且一切正常。