Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.3 - Troubleshooting 500 Errors - Debugging - Parse Errors

Occasionally I will have some badly formed PHP code and I will get a 500 error. I'm running Apache 2.2 on a Windows 7 laptop. As an IDE I have started using PhpStorm.

What is the best way to catch these errors and be informed of the line number? Why do the OOP-related syntax errors tend to throw 500 errors and function problems tend to return normal errors?

Example of syntax mistake: calling a static method from a class with a single colon instead of two colons.

UPDATE: Please see accepted answer and all comments.

like image 297
BuddyJoe Avatar asked Dec 19 '11 16:12

BuddyJoe


1 Answers

PHP will respond with a "500" when it encounters a Fatal error, such as E_PARSE, E_ERROR and uncaught exceptions. 500 is the HTTP response code for "Internal Server Error" - something unrecoverable happened while processing the request.

In your php.ini, on a development machine, you should set your error_reporting level to (at least) E_NOTICE - preferably E_ALL - and make sure display_errors is on. This will show you the error message in the browser, including for "500" errors.

You can also check your Apache error logs, the errors will be listed there, as long as log_errors is enabled in php.ini. By default, this will be at <apache_ServerRoot>\logs\error.log.

You can also control all this at run time with ini_set() and error_reporting()

like image 133
DaveRandom Avatar answered Sep 20 '22 18:09

DaveRandom