174

This has never happened before. Usually it displays the error, but now it just gives me a 500 internal server error. Of course before, when it displayed the error, it was different servers. Now I'm on a new server (I have full root, so if I need to configure it somewhere in the php.ini, I can.) Or perhaps its something with Apache?

I've been putting up with it by just transferring the file to my other server and running it there to find the error, but that's become too tedious. Is there a way to fix this?

Rob
  • 7,980
  • 30
  • 75
  • 115
  • 3
    That sounds like an apache problem, not a PHP problem. Apache will throw a 500 any time it has configuration issues (like bad syntax in .htaccess). Check your apache error log for an error message. – Frank Farmer Apr 22 '10 at 01:48

7 Answers7

263

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

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

After that, restart server.

Davide
  • 1,635
  • 1
  • 16
  • 29
awgy
  • 16,596
  • 4
  • 25
  • 18
  • 1
    How do we turn off display_errors, yet have PHP display 200 or 404 instead of 500? – Pacerier Jul 22 '13 at 16:11
  • 1
    Not sure if it was in 2010 but, you don't need to restart the server (unless using an opcode cache like APC) in 2014. – Czar Pino Aug 16 '14 at 11:20
  • 1
    Even after doing all that I still get the 500 error... perhaps it is coming from IIS? – Kellen Stuart Oct 12 '17 at 22:52
  • 2
    Sometimes wrong permissions in a Linux environiment can lead to a 500 error too. Just as a reminder. – Fusseldieb Nov 22 '17 at 09:56
  • 1
    If you cannot modify php.ini, you can add a .htaccess file with `php_flag display_errors 1` – Tom Jan 16 '19 at 10:57
  • the latter way(i.e. adding that two lines setting at the very beginning) doesn't work for me when I deal with jquery, buf the former works for me. Thanks! – weiweishuo Oct 20 '19 at 12:27
  • I tried this and am still getting literally "Oops! An Error Occurred The server returned a "500 Internal Server Error". Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused." from MAMP Pro on macOS Monterey Apache. – SteveExdia May 09 '22 at 20:48
27

Use php -l <filename> (that's an 'L') from the command line to output the syntax error that could be causing PHP to throw the status 500 error. It'll output something like:

PHP Parse error: syntax error, unexpected '}' in <filename> on line 18

Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
Aaron
  • 583
  • 1
  • 5
  • 12
  • 4
    This really helped me out! Tail'ing my error log produced nothing, but this gem worked perfectly and displayed my syntax error and the line number. Was debugging a Class file. Thanks! – Source Matters Mar 19 '17 at 03:50
  • This is the true answer here, quick and easy for us lazy folks :P – Petro Mar 07 '20 at 13:35
  • On Windows I installed Xammp so I could have php.exe on my machine to do this – Matthew Lock Aug 17 '21 at 09:57
17

It's worth noting that if your error is due to .htaccess, for example a missing rewrite_module, you'll still see the 500 internal server error.

dtbarne
  • 8,110
  • 5
  • 43
  • 49
  • 3
    I was actually missing a module on apache. I got that by looking the error log (default for ubuntu is /var/log/apache2/error.log) – Eduardo Mello Mar 04 '15 at 13:07
10

Be careful to check if

display_errors

or

error_reporting

is active (not a comment) somewhere else in the ini file.

My development server refused to display errors after upgrade to Kubuntu 16.04 - I had checked php.ini numerous times ... turned out that there was a diplay_errors = off; about 100 lines below my

display_errors = on;

So remember the last one counts!

Max
  • 2,561
  • 1
  • 24
  • 29
6

Try not to go

MAMP > conf > [your PHP version] > php.ini

but

MAMP > bin > php > [your PHP version] > conf > php.ini

and change it there, it worked for me...

von verletzt
  • 114
  • 1
  • 5
3

Enabling error displaying from PHP code doesn't work out for me. In my case, using NGINX and PHP-FMP, I track the log file using grep. For instance, I know the file name mycode.php causes the error 500, but don't know which line. From the console, I use this:

/var/log/php-fpm# cat www-error.log | grep mycode.php

And I have the output:

[04-Apr-2016 06:58:27] PHP Parse error:  syntax error, unexpected ';' in /var/www/html/system/mycode.php on line 1458

This helps me find the line where I have the typo.

Hao Nguyen
  • 528
  • 4
  • 10
0

If all else fails try moving (i.e. in bash) all files and directories "away" and adding them back one by one.

I just found out that way that my .htaccess file was referencing a non-existant .htpasswd file. (#silly)

WoodrowShigeru
  • 1,418
  • 1
  • 18
  • 25