2017-06-08 86 views
1

我已經在AWS Elastic Beanstalk上部署了一個基於Yii2的應用程序,我還創建了帶有數據庫的RDS實例(它已經有表)在Elastic Beanstalk上。所有文件都正確上傳到AWS實例。PDO異常SQLSTATE [HY000] [2002]在Yii2上使用Elastic Beanstalk和RDS連接超時

文件/common/config/main-local.php有:

'components' => [ 
     'db' => [ 
      'class' => 'yii\db\Connection', 
      'dsn' => 'mysql:host=myConnection_string:3306;myDB', 
      'username' => 'myUsername', 
      'password' => 'myPassword', 
      'charset' => 'utf8', 
     ], 

有什麼不對?謝謝。

回答

0

我通過在EC2> Network &安全>安全組>編輯入站規則中更改爲「所有流量」來解決該問題。

我也設置在AWS上的變量,改變了腳本:

'components' => [ 
    'db' => [ 
     'class' => 'yii\db\Connection', 
     'dsn' => 'mysql:host=', 
     'dsn' => 'mysql:host='.$_SERVER['RDS_HOSTNAME'].':'.$_SERVER['RDS_PORT'].';dbname='.$_SERVER['RDS_DB_NAME'], 
     'username' => $_SERVER['RDS_USERNAME'], 
     'password' => $_SERVER['RDS_PASSWORD'], 
     'charset' => 'utf8', 
    ], 

這個答案我有很大幫助:How to connect to an RDS database from Yii2?

相關問題