Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Makbel's avatar
Level 1

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it

Mostly whenever I start my laragon server and try to run ' php artisan serve' on my terminal, The error ' No connection could be made because the target machine actively refused it' shows up. Even though after i restart my pc and do the same thing it works just fine , i am looking a better solution here since i don't want to restart pc every time i want to open up a project. I use

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306

for all of my projects in their .env file.

I've tried netstat -aon | findstr 3306 to see if anything occupied the port, but nothing shows up.

0 likes
5 replies
Maelfjord's avatar

Did you check if the MySQL service is running?

Maelfjord's avatar

@Makbel Try checking if the MySQL service hostname is 'localhost', the port is '3306', or the password if it is set.

If that doesn't work, it's probably a network connection problem. You might need to configure MySQL settings or your firewall settings.

JussiMannisto's avatar

If there's nothing listening on port 3306, then clearly the mysql server isn't listening on it either. You need to be running the mysql server in order to connect to it.

jlrdw's avatar

whenever I start my laragon server and try to run ' php artisan serve'

Why not use Apache?

Please or to participate in this conversation.