# Server error everytime there is a php error

I keep getting

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.


Whenever there is something wrong with my php code. I am using ubuntu 11.04 with apache2 and php installed.

-
And your question is how to code better in php? ;-) –  Rinzwind Sep 11 '11 at 18:52
I guess you want to have the PHP error visible instead of Apache's response? –  Lekensteyn Sep 11 '11 at 18:58

If you're looking to debug your php code you'll want to run tail -f /var/log/apache2/error.log this will have detailed information about why the 500 error was triggered.

Here is an example from my error log that recently threw a 500 error

[Sun Sep 11 22:54:16 2011] [error] [client 127.0.0.1] PHP Fatal error: Call to a member function sql_query() on a non-object in /home/marco/Projects/Ondina/cp/apps/domains/databases.d.php on line 170

This shows the file source that threw the error, the line, and the exact error message. From those three variables you should be able to locate and fix any issues with your code.

-

You can enable display_errors and disable log_errors in the php.ini file ( /etc/php5/apache2/php.ini ). But note that for a live site it is much better to log errors than to show an error on the web page, because such an error may contain information which you don't want to leak.

-