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

greevesh's avatar

Laravel 6.0 and PHP 7.4: SQLSTATE[HY000] [2002] No such file or directory

I just upgraded my PHP version from 7.2 to 7.4 and now whenever I try to run a query, I get this error. Here are my relevant .env credentials:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306

I've tried as many have suggested and tried changing the DB_HOST to 127.0.0.1 and I get this error instead:

SQLSTATE[HY000] [2002] Connection refused

This is the first time I've ever performed a PHP upgrade. Is it normal to have issues like this? Particularly with Laravel?

Thanks

0 likes
5 replies
Tray2's avatar

Can you connect to the database from the command line?

mysql -u root -p

Replace root with your mysql username if you have another one.

1 like
greevesh's avatar

Root is the only username I have. I tried connecting through the terminal and I got the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
greevesh's avatar

All I needed to do was start MySQL. That would explain why the restart commands weren't working. I never disconnected from MySQL manually but I read on SO that if you have multiple instances of MySQL, problems like these can take place. This makes sense as I recently installed XAMMP.

Maybe it wasn't the PHP upgrade after all.

Thank you both.

Please or to participate in this conversation.