Website returns HTTP 500 when testing PDO/MySQL connection

Website URL

https://jtncrit.freehosting.dev/login.php

Error Message

HTTP 500

Other Information

The issue occurs on my InfinityFree-hosted website. A basic PHP test works, and including config/security.php also works. However, both login.php and db_check.php return HTTP 500.

The database settings use the MySQL hostname, database name, and username provided by InfinityFree. PDO and PDO MySQL are enabled.

I have kept PHP display_errors disabled for security.

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 HTTP 500 means the PHP code crashed, but it doesn’t say why. To see the real error, turn on Display Errors in the control panel. The knowledge base article on this says to go to Alter PHP Config, select your domain, click Alter PHP Directives, set “Display Errors” to “On” and save. Then reload db_check.php.

If you still get a blank 500, your own code may be overriding that setting. Look for ini_set('display_errors', 0); or error_reporting(0); in db_check.php, login.php or any file they include. Your config/security.php is a good place to check, even though it loads fine on its own. Comment those lines out while you debug.

I didn’t find anything about reading server-side PHP error logs, so I can’t point you to one. Showing the errors temporarily is the method the article describes. You can turn Display Errors off again once it’s fixed.

Here is the article:

If the crash is in the database connection, wrap it in try { ... } catch (PDOException $e) { echo $e->getMessage(); }. The MySQL article says PDO throws a PDOException you can print. It also lists the common causes: the wrong hostname, a database name or username that’s missing its account prefix, and using the client area password instead of the hosting account password.

If that doesn’t settle it, post the exact error message you see, without the password. Also say whether db_check.php is the first file to touch the database, or whether config/security.php does too.