Error: "SQLSTATE[HY000] [2002] Connection refused" in Laravel Homestead
When working with a Laravel project within Homestead, you may encounter a "SQLSTATE[HY000] [2002] Connection refused" error when running PHP Artisan commands.
Potential Cause and Solution:
The error indicates that the database connection failed, likely due to an incorrect configuration. From the information provided, it appears that the issue lies with the database host setting in the .env file.
To resolve this, ensure that the DB_HOST value in .env is set to localhost instead of 127.0.0.1. This is because Homestead uses a self-contained MySQL server running on port 33060, which is accessible via the localhost alias.
Alternative Solutions to Explore:
The above is the detailed content of How to Fix \'SQLSTATE[HY000] [2002] Connection refused\' Error in Laravel Homestead?. For more information, please follow other related articles on the PHP Chinese website!