SQLSTATE[HY000] [2002] Connection refused within Laravel homestead
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Troubleshooting SQLSTATE[HY000] [2002] Connection refused errors in Laravel Homestead
Introduction:
Using Laravel with Homestead is an efficient way to develop and manage your web application on a local environment. However, issues can sometimes arise during the development process, particularly when dealing with database connections. Today, we'll dive into troubleshooting the common "SQLSTATE[HY000] [2002] Connection refused" error within Laravel Homestead.
Issues with database connection configuration:
Ensuring your database configuration is set up correctly can prevent these errors from occurring. Here are some possible reasons for these kinds of issues:
1. Incorrect hostname/IP address: Make sure you've provided the correct IP address (usually 127.0.0.1) or hostname (local machine name, if applicable). It's essential to set it up correctly in both the .env file within your Laravel project and in Sequel Pro for successful database management.
2. Incorrect port number: Homestead uses a default port (33060) for your local development environment; make sure you match this in your database configuration settings.
3. Wrong credentials: Double-check that the username, password, and database name being used are accurate. If you're unsure of the right values to use, ensure they were set up correctly during the initial installation process or when creating the database.
4. Firewall issues: In some cases, firewalls can interfere with establishing a connection between your Laravel project and the local database (Sequel Pro). Disabling your firewall temporarily might resolve this issue, but it's always better to configure an exception for your local environment IP addresses or hostnames in your system-wide firewall settings.
Troubleshooting steps:
Now that we've addressed some possible reasons for the "SQLSTATE[HY000] [2002] Connection refused" error, here are a few troubleshooting steps to follow if you still encounter this issue:
1. Check your .env file and ensure all database configuration settings are accurate. Make sure the values match those used in Sequel Pro or any other database management tool you may be using.
2. Restart your Homestead environment. Open your terminal, navigate to the project folder, and run "homestead up" to stop and restart the virtual machine. This will refresh the environment's settings and potentially fix minor issues that might have been causing the connection problems.
3. If you're using MAMP (Mysql, Apache, PHP), ensure your database configuration is correct within MAMP settings. Be sure that your database hostname and credentials match those used in Laravel Homestead. Then, try to run php artisan migrate from the terminal.
4. If the error persists despite these troubleshooting steps, it may be time to reinstall Homestead and Laravel from scratch. Make sure you have a recent backup of your project before proceeding with this method.
Conclusion:
The "SQLSTATE[HY000] [2002] Connection refused" error in Laravel Homestead can result from a variety of issues, but following the troubleshooting steps outlined above should help resolve them. It's crucial to have proper database configuration and firewall setup for your local development environment to function correctly and ensure smooth connections between your Laravel project and its associated databases.
Remember that if you need additional support during your Laravel development journey, feel free to consult the resources provided by https://laravelcompany.com/blog/.