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

BlueSilver's avatar

SQLSTATE[HY000] [2002] Connection refused on shared hosting

I connect with vanilla php statement on shared hosting and on the local machine to that machine. But it doesn't work my shared hosting.

DB_CONNECTION=mysql DB_HOST=mysql.loopia.se DB_PORT=3306 DB_DATABASE=databasename DB_USERNAME=username DB_PASSWORD=password

0 likes
8 replies
gych's avatar

Are you using an external db or is the db host mysql.loopia.se on the same server as your application ?

BlueSilver's avatar

@gych I don't know. I tried it as extrenal db and it works in pure php but not in laravel

gych's avatar

@BlueSilver When you tried it with vanilla php, was that on the same server you can't make the connection with laravel ?

BlueSilver's avatar

@gych I tried it on shared hosting with vanilla php and it works. It is with Laravel that is not working.

gych's avatar
gych
Best Answer
Level 29

@BlueSilver Try to run php artisan config:clear to clear the cached config.

leonardodecuritiba's avatar

Did you tried to connect in SQL via command line? Maybe you have a mistake in DB_HOST variable.

Please or to participate in this conversation.