Laravel "Connection refused" Error During Database Migration
Problem Description:
When deploying a Laravel application on a Digital Ocean VPS, users encounter a runtime error "SQLSTATE[HY000] [2002] Connection refused" while attempting database migrations. This error indicates a problem with the database connection.
Root Cause:
The root cause of this error is an incorrect database host specified in the .env file.
Solution:
To resolve this issue, ensure that the DB_HOST variable in your .env file is set to 'localhost' instead of the server's IP address. This will redirect the database connection to the correct host running on the VPS.
Here is the revised .env file with the corrected DB_HOST:
APP_ENV=local APP_KEY=my app key APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=form DB_USERNAME=root DB_PASSWORD=my pass
Additional Considerations:
The above is the detailed content of Here are some question-based titles that fit the content: * Laravel \'Connection Refused\' Error During Migration: How to Fix the Database Host Issue? * Why Am I Getting a \'Connectio. For more information, please follow other related articles on the PHP Chinese website!