How to Solve SQLSTATE[HY000] [2002] No connection In Laravel

In this section, we’ll address how to resolve the SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it error in Laravel.

SQLSTATE[HY000] [2002] No connection

Laravel Solve SQLSTATE[HY000] [2002]

If you encounter this error, please ensure that your XAMPP connection is active. If it’s inactive, turn on both MySQL and Apache services.

 xampp connection solve SQLSTATE[HY000] [2002]

If the previous solution doesn’t resolve the issue, you can try the following steps:

  1. Modify the .env file by changing the host from 127.0.0.1 to localhost.
  2. Run the Laravel config cache command using php artisan config:cache.
  3. Verify the config/database.php file to see if there are any changes or misconfigurations.

These steps may help in resolving the SQLSTATE[HY000] [2002] error.

saim ansari
saim ansari

I'm Saim Ansari, a full-stack developer with 4+ years of hands-on experience who thrives on building web applications that leave a lasting impression. When it comes to tech, I'm particularly adept at Laravel, React, Tailwind CSS, and the Tall Stack