Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
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

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.