Php Errors are logged in server , screen only shows 500 internal


#1

Hi folks,

strange, my php scripts when execute, if there is any syntax error, i have to open and see the error_log in server’s script folder. The screen shows only

This page isn’t working

example.com is currently unable to handle this request.

HTTP ERROR 500

The above is shown for the following error loged in error_log,

[12-Dec-2018 17:27:39 UTC] PHP Parse error: syntax error, unexpected ‘}’, expecting ‘,’ or ‘;’ in /home/accessto/public_html/demo3/admin/content/dashboard/pages/client_admin/photo_manager/add_pkg_photo.php on line 86

my declaration as follows

<?php
error_reporting(E_ALL);
error_reporting(-1); 
ini_set('display_errors', 'true');

i want errors to show on screen for easy troubleshooting. but can turn off when site is launched. so what configuration i need to adjust?


#2

Shared hosting environments typically will not allow you to show those errors in the browser because doing so introduces a security vulnerability.


#3

Here is a possible SO Solution:

As we are now running PHP7, answers given here are not correct anymore.
The only one still OK is the one from Frank Forte, as he talks about PHP7.
On the other side, rather than trying to catch error with a try/catch you can use a trick:
use include.
Here 3 pieces of code:

File: tst1.php

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
// Missing " and ;
echo "Testing
?>

Running this in PHP7 will show nothing

Now, try this:

File: tst2.php

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
include ("tst3.php");
?>

File: tst3.php

<?php
// Missing " and ;
echo "Testing
?>  

Now run tst2 which set the error reporting then include tst3. You will see:

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in tst3.php on line 4


closed #5

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.