Why do I get a SQLSTATE[HY000] [2002] Connection refused error when running an artisan command in my EC2 instance?


I have a Laravel web app set up on Elastic Beanstalk and it can connect to the RDS database just fine. I have the environment variables set up through the configuration setting in EB. When I ssh into the EC2 instance and run a custom artisan command that queries the database like "sudo php artisan check-companies", I get the error SQLSTATE[HY000] [2002] Connection refused (SQL: the query)". What could be causing this error? Here are a few things to note and what I’ve tried.

  1. I have workers that run the same artisan command every day and it works.
  2. I’m able to connect to the Aurora Cluster from MYSQL command line utility and run queries when I ssh into the instance.
  3. I’ve tried exposing the environment variables to the instance as shown here: https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-shell/
  4. I made sure port 3306 is open in my security group

Source: Laravel


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us