PHP cannot connect to MySQL on sql305.infinityfree.com

Website URL

https://bantay.site.je

Error Message

My website is hosted on InfinityFree account if0_43250058, domain bantay.site.je. PHP cannot connect to my MySQL database on sql305.infinityfree.com. It returns SQLSTATE[HY000] [2002] No such file or directory, but the database and tables are visible in phpMyAdmin. Can you check the MySQL connection from my hosting account and advise how to make the app’s storage directories writable by PHP?

Other Information

The database and its tables are visible in phpMyAdmin. The website homepage loads, but the API health endpoint fails. The error shown is SQLSTATE[HY000] [2002] No such file or directory. Please check the MySQL connection from this hosting account and advise how to make the backend storage directories writable by PHP.

Welcome to the InfinityFree community forum! Good to have you here.

  • Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
  • Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
  • AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
  • Solving an issue is a joint effort. Try the suggestions you get and report back what happened.

Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.

The No such file or directory error usually means the app is connecting with localhost as the database host, not sql305. Our article on common MySQL connection errors says that message appears when localhost is the hostname, because the script then looks for a database on the same server as your site, and that doesn’t work here.

Link to the article:

phpMyAdmin showing your tables doesn’t rule this out. It uses the right host on its own, while your app uses whatever its config says. If your app reads its settings from a .env file or a similar config, check that the file really has the host you expect. A default of localhost can be used when a value is missing or misnamed.

Could you post the lines of your connection code or config that set the host, database name and username, with the password removed? Also say whether the API health endpoint reads them from a .env file or has them written in the code.

I couldn’t find anything on the forum or in the knowledge base about making storage directories writable for PHP. If you still need that after the connection works, tell me which framework or app this is and the exact error you get when it tries to write.