Launching Yii2 on AWS with RDS

Hello everyone,

I’m trying to launch my application on AWS. I am not having the greatest of luck. I’ve managed to get the application uploaded and accessible. However, I am trying to get the database connection to work.

I have updated my db parameter settings according to this answer on Stack Overflow.

Still despite updating the parameters, I still get the following error:

SQLSTATE[HY000] [2002] Connection refused

Caused by: PDOException

SQLSTATE[HY000] [2002] Connection refused

I tried switching the security group rules to allow all inbound traffic, but this too did not help.

Any and all guidance would be appreciated it. I have been fighting this for a few days and have followed the guides on AWS to the T. I have created and destroyed several environments and databases at this point lol.

If someone has launched yii2 on AWS ElasticBeanstalk, I would greatly appreciate some guidance as I am lost.

Thanks in Advance

This is an example of a RDS database connection:

'dsn' => ';dbname=DBNAME',

Are you trying to connection from your localhost or from another EC2 instance?

1 Like

Trying to connect from another EC2 instance. Here’s what I have in the config file:

'dsn' => 'mysql:host='.$_SERVER['RDS_HOSTNAME'].':'.$_SERVER['RDS_PORT'].';dbname='.$_SERVER['RDS_DB_NAME'],
'username' => $_SERVER['RDS_USERNAME'],
'password' => $_SERVER['RDS_PASSWORD'],

Using the guide on AWS, it indicated I could use system variables. I just pulled this up:

Looks like the inputs may not be properly formatted. Going to try to update and see if this helps. Will report back.

Tried updating the connection string to the following:

'dsn' => 'mysql:host='.$_SERVER['RDS_HOSTNAME'].';port='.$_SERVER['RDS_PORT'].';dbname='.$_SERVER['RDS_DB_NAME'],
'username' => $_SERVER['RDS_USERNAME'],
'password' => $_SERVER['RDS_PASSWORD'],

Still no luck.

Maybe i am wrong, but why don’t you just connect to the RDS system trough the configuration given from AWS? Like the example you can see from my previous comment. Open the RDS view where all database are listed, then you can see the informations for a given Database in order to connect.

The documentation link from above is seems to be regardings beanstalk - not sure - just took a quick look at the breadcrumbs :slight_smile:

AWS Documentation » AWS Elastic Beanstalk » Developer Guide » Creating and Deploying PHP Applications on AWS Elastic Beanstalk » Adding an Amazon RDS DB Instance to Your PHP Application Environment

According to your error you’re security group for your server isn’t correct. You need to make sure that your inbound rule on your servers security group for (or your Internal AWS Connections) is set to “all” (or just the specific port(s) you are using). This way your server can talk to your DB.

I finally was able to get the server to connect with the DB. In truth, I didn’t do anything different. I deleted everything and started over, following their guide.

Now my next question is, how do I access the console in order to do the database migrations? Not sure how to reach the source files from a command line.

Some guidance would be great here.