Home > Database > Mysql Tutorial > body text

Here are a few title options for your article, focusing on the question format: * Laravel on VPS: Why am I getting \'SQLSTATE[HY000] [2002] Connection Refused\'? * How to Fix \'SQLSTA

DDD
Release: 2024-10-28 10:01:30
Original
791 people have browsed it

Here are a few title options for your article, focusing on the question format:

* Laravel on VPS: Why am I getting

Troubleshooting "SQLSTATE[HY000] [2002] Connection Refused" Error in Laravel

When deploying a Laravel application to a VPS, you may encounter the "SQLSTATE[HY000] [2002] Connection refused" error. This issue arises primarily due to an incorrect database host configuration.

Cause:

Your .env file specifies the database host as "my ip", which likely represents the server's IP address. By default, Laravel assumes a localhost connection unless explicitly instructed otherwise.

Solution:

To resolve the error, modify your .env file to use "localhost" as the DB_HOST value. Here's the updated .env configuration:

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
Copy after login

Explanation:

By setting DB_HOST to "localhost", you instruct Laravel to connect to the MySQL database running locally on the VPS. This ensures that the application can access the database successfully.

Once you modify the .env file, run the following command to recreate the database connection:

php artisan migrate
Copy after login

If the migration command completes without errors, the issue should be resolved.

The above is the detailed content of Here are a few title options for your article, focusing on the question format: * Laravel on VPS: Why am I getting \'SQLSTATE[HY000] [2002] Connection Refused\'? * How to Fix \'SQLSTA. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!