Home > Article > Backend Development > Why Am I Getting \"SQLSTATE[HY000] [2002] Connection Refused\" Error During Laravel Homestead Migrations?
Resolving "SQLSTATE[HY000] [2002] Connection refused" Error in Laravel Homestead
When attempting to perform database migrations within Laravel's Homestead environment, you may encounter the "SQLSTATE[HY000] [2002] Connection refused" error. This issue stems from a configuration discrepancy between your Homestead settings and the database connection details specified in your .env file.
Troubleshooting the Connection Issue
Verify the Database Connection Settings:
Ensure that the database connection settings in your .env file match the credentials used to connect to the database via Sequel Pro. Double-check the host, username, password, and database name.
Adjust the Database Host:
In your .env file, try changing the DB_HOST setting from 127.0.0.1 to localhost. This may resolve the connection issue as Homestead uses localhost to refer to the internal database.
Check Homestead IP Address:
Confirm that Homestead's IP address is set to 127.0.0.1 in your homestead.yaml file located within the ~/.homestead directory. This ensures that both Laravel and Homestead can access the database.
Restart Homestead:
Restart Homestead using vagrant halt and vagrant up commands to apply any changes made to the configuration.
Additional Tips
The above is the detailed content of Why Am I Getting \"SQLSTATE[HY000] [2002] Connection Refused\" Error During Laravel Homestead Migrations?. For more information, please follow other related articles on the PHP Chinese website!