Connection Refused Error with Laravel Homestead
Laravel Homestead, a popular development environment, sometimes encounters connection refused errors when executing commands like php artisan migrate. A user recently faced this issue while running the command and encountered the error "SQLSTATE[HY000] [2002] Connection refused."
Troubleshooting the Issue
The user provided details of their configuration, including the settings within their .env file:
DB_HOST=127.0.0.1 DB_DATABASE=tcv DB_USERNAME=homestead DB_PASSWORD=secret
They had also attempted using various combinations of localhost and root for DB_HOST, DB_USERNAME, and DB_PASSWORD, but the error persisted.
Solution
While the user was able to connect to the database using Sequel Pro with the same configuration settings, it was revealed that changing the DB_HOST setting in the .env file from 127.0.0.1 to localhost resolved the issue. The migration command could then be executed successfully.
The above is the detailed content of Why Does Laravel Homestead\'s \'php artisan migrate\' Throw \'Connection Refused\' Error?. For more information, please follow other related articles on the PHP Chinese website!