Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP not displaying errors - Internal Server Error (500)

I've set up a fresh install of Ubuntu Server 12.04 LTS on Amazon AWS with *Apache2/MySQL/PHP5. When I run a PHP script and it encounters an error I don't see any error reporting from PHP, all I see is

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

I have checked my /etc/php5/apache2/php.ini file and as far as I can tell error reporting should be set up. The contents of the file (regarding errors) are:

;    display_errors
;      Default Value: On
;      Development Value: On
;      Production Value: Off

;    display_startup_errors
;      Default Value: Off
;      Development Value: On
;      Production Value: Off

;    error_reporting
;      Default Value: E_ALL & ~E_NOTICE
;      Development Value: E_ALL | E_STRICT
;      Production Value: E_ALL & ~E_DEPRECATED

Can anyone advise? If I try something like $obj = new ObjectDoesntExist; it doesn't tell me Fatal error: Class 'ObjectDoesntExist' it gives me a server 500 error.

Any advise?

* The modules I have installed are: mysql-server mysql-client apache2 php5 libapache2-mod-php5 phpmyadmin. Other than that it is a completely base install of Ubuntu Server 12.04 LTS

EDIT: If I use ini_set('display_errors', '1'); at the start of my script it displays errors as normal, but how do I enable this site wide?

like image 937
iainjames88 Avatar asked Jul 31 '12 21:07

iainjames88


People also ask

How do I fix a 500 Internal server error?

Clear your browser cache and cookies Check these articles on deleting the cache on an Android phone or iPhone, if you use a mobile device. Alternatively, you can test opening the page from another browser. For instance, if you use Chrome, try Firefox or vice versa.

What causes 500 errors PHP?

PHP Coding Timing Out If your PHP script makes external network connections, the connections may time out. If too many connections are attempted and time out, this will cause a "500 Internal Server Error." To prevent these time outs and errors, you'll want to make sure that PHP scripts be coded with some timeout rules.

How can I make PHP display the error instead of giving me 500 Internal server error?

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).


2 Answers

The php.ini snippet you pasted has a semicolon (the ; character) in each line. The semicolon is the start of a comment in php.ini, so everything in a line following a semicolon is not used. Try manually setting display_errors to on and error_reporting to E_ALL, or removing the appropriate semicolons to fix this.

Furthermore, check your apache's error log, php might be logging its errors there.

like image 104
Wouter Avatar answered Oct 09 '22 03:10

Wouter


please edit the php.ini file by using the sudo gedit /etc/php5/apache2/php.ini and on the Production Value,or you can also use the ini_set('display_errors', '1'); at the top of your php file

like image 21
user2779489 Avatar answered Oct 09 '22 04:10

user2779489