search

Home  >  Q&A  >  body text

How can I get PHP to show the error instead of giving me a 500 Internal Server Error

This has never happened before. Normally it would show an error, but now it just gives me a 500 Internal Server Error. Of course before, when it showed the error, it was a different server. Now I'm on a new server (I have full root so if I need to configure it somewhere in php.ini I can.) Or maybe it's an Apache thing?

I've been putting up with it and just transferring the files to my other server and running it there to find errors, but it's getting too tedious. Is there a way to solve this problem?

P粉930534280P粉930534280396 days ago672

reply all(2)I'll reply

  • P粉885562567

    P粉8855625672023-10-15 09:02:36

    Using php -l <​​filename> (i.e. "L") from the command line outputs syntax errors that may cause PHP to throw a status 500 error. It will output the following:

    PHP parsing error: Syntax error, unexpected "}" in line 18

    reply
    0
  • P粉738676186

    P粉7386761862023-10-15 00:29:18

    Check the error_reporting, display_errors and display_startup_errors settings in the php.ini file. They should be set to E_ALL and "On" respectively (although you should not use display_errors on a production server, so disable this option and use < code>log_errors Instead, if/when you deploy it). You can also change these settings (except display_startup_errors) at the beginning of the script so that they are set at runtime (although you may not catch all errors this way):

    error_reporting(E_ALL);
    ini_set('display_errors', 'On');

    After that, restart the server.

    reply
    0
  • Cancelreply