无法连接到已部署的App Elastic Beanstalk中的RDS

时间:2018-08-27 18:04:40

标签: laravel amazon-web-services amazon-rds

我有一个连接到RDS数据库的Laravel应用程序,在localhost中它可以正常工作,但是当我将该应用程序部署到Elastic Beanstalk中时,它就无法工作。

与mysql的连接:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => 'dbpassword',
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],

DB_CONNECTION=mysql
DB_HOST=dbname.ctwrtyncfghj.us-east-1.rds.amazonaws.com
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=dbUser

要部署,我会压缩除供应商/以外的所有文件。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,所以我将编写包含2个步骤的解决方案:

1。从Laravel到AWS文档的RDS连接因此需要完成:

a。在config / database.php中添加define语句:

define('RDS_HOSTNAME', $_SERVER['RDS_HOSTNAME']);
define('RDS_USERNAME', $_SERVER['RDS_USERNAME']);
define('RDS_PASSWORD', $_SERVER['RDS_PASSWORD']);
define('RDS_DB_NAME', $_SERVER['RDS_DB_NAME']);
define('RDS_PORT', $_SERVER['RDS_PORT']);

b。并更改mysql配置:

'mysql' => [
            'driver' => 'mysql',
            'host' => RDS_HOSTNAME,
            'port' => RDS_PORT,
            'database' => RDS_DB_NAME,
            'username' => RDS_USERNAME,
            'password' => RDS_PASSWORD,
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ]

2。必须将来自AWS EB App的RDS连接视为VPC(https://aws.amazon.com/documentation/vpc/):

a。该视频完全显示了如何正确配置VPC和子网以使用EB

https://www.youtube.com/watch?v=udY8x_g0dTk&frags=pl%2Cwn

b。创建VPC和子网后,您需要创建一个全新的EB环境并连接到VPC和子网

https://www.youtube.com/watch?v=CB6YzVBxiL4&frags=pl%2Cwn