2

I have an elastic beanstalk ec2 (Amazon Linux 2023) instance and a RDS database (MariaDB 10.11) created inside same region and using same VPC, my databse is accessible only via ssh tunneling, i have a laravel app deployed in the ec2 with following .env credentials for database :

RDS_HOSTNAME=prod-example-db.dafsfduieeikka0.eu-west-1.rds.amazonaws.com
RDS_PORT=3306
RDS_DB_NAME=db_name
RDS_USERNAME=db_username
RDS_PASSWORD=mydbpassword

following aws ebs documentation for deploying laravel app I have modifed a portion of the config/database.php file of laravel as following:

'host' => env('RDS_HOSTNAME', '127.0.0.1'),
'port' => env('RDS_PORT', '3306'),
'database' => env('RDS_DB_NAME', 'forge'),
'username' => env('RDS_USERNAME', 'forge'),
'password' => env('RDS_PASSWORD', ''),

Now i'm getting SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'ip_address' (using password: YES) when i try to visit my site, Can someone tell me what is the problem? Do i have to create a ssh tunnel from inside the ec2 to the RDS db to allow the connection?

8
  • 2
    The fact that it is saying Access Denied means that it is successfully connecting to the Amazon RDS database, but the database is rejecting the connection. So, your network configuration and security groups seem to be operating fine. Either you have the wrong database, username or password OR you make Laravel use secure SSL connection while using AWS RDS — Tech.Semicolon. Amazon RDS will reject a connection that is not using SSL. Commented Apr 6, 2024 at 11:14
  • @JohnRotenstein according to this doc by aws [docs.aws.amazon.com/AmazonRDS/latest/UserGuide/…, MaridaDB RDS instances does not require SSL by default, and i haven't turned it on. Commented Apr 6, 2024 at 17:01
  • @JohnRotenstein also i've been successful on connecting to the RDS database via ssh tunnel from my local machine database client (DBeaver) with the same database credentials (host name, username, password etc) and the private key for the ec2. Commented Apr 6, 2024 at 17:22
  • 1
    Try to SSH to your EC2 instance and run the command mysql -u db_username -p'mydbpassword' -h prod-example-db.dafsfduieeikka0.eu-west-1.rds.amazonaws.com db_name. Does it allow you to connect successfully? Commented Apr 6, 2024 at 17:45
  • @EyadBereh yes i can connect to the RDS database from my ec2 terminal with the above command you wrote, i can even execute queries successfully, But it is still showing access denied when i visit my laravel app from the browser. Commented Apr 6, 2024 at 18:06

1 Answer 1

0

Just used quotes around my password in the .env file and this solved my issue.

RDS_PASSWORD='mydbpassword'

Thank you guys.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.