Home >Database >Mysql Tutorial >How to Fix the \'SQLSTATE[HY000] [2002] Connection refused\' Error During Laravel Migration on a Digital Ocean VPS?
Troubleshooting "SQLSTATE[HY000] [2002] Connection refused" Error in Laravel Migration
During Laravel project deployment to a Digital Ocean VPS, the "SQLSTATE[HY000] [2002] Connection refused" error can arise during database migration. This error indicates that the database connection could not be established.
After examining the provided .env file configuration, we identify the issue lies in the DB_HOST setting. In the provided configuration, DB_HOST is set to the VPS's IP address, which may not be accessible from the Laravel application.
Solution:
To resolve this error, we need to modify the DB_HOST setting in the .env file to point to the MySQL server's hostname. Specifically, we will change DB_HOST from the VPS's IP address to "localhost." This will ensure that the Laravel application connects to the MySQL server running on the same machine.
The above is the detailed content of How to Fix the \'SQLSTATE[HY000] [2002] Connection refused\' Error During Laravel Migration on a Digital Ocean VPS?. For more information, please follow other related articles on the PHP Chinese website!