So, I don’t really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bit and thought adding these two lines would fix everything.
ini_set('display_errors', 'On'); error_reporting(E_ALL);
NOTE: I don’t have access to the php.ini file, as I’m using my school account’s server.
So I introduced a bug (no semicolon after $buggy) like so at the top of my page:
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $buggy $x = 4 + 2; ...
However, I just get a Server error:
“The website encountered an error while retrieving http://mywebpage.com/. It may be down for maintenance or configured incorrectly.”
I’ve reconfigured my code:
<?php include_once 'database/errorSettings.php'; ?> <?php $buggy // whoops $x = 4 + 2; ...
errorSettings.php is the following:
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); ?>
But it still doesn’t work… wrong way to reconfigure?
What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there’s a parse error in the file where you’re setting your error levels, they won’t have taken effect by the time the error is thrown.
Either break your files up into smaller parts, like setting the error levels in one file and then
includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.
You need to set the error_reporting value in a .htaccess file. Since there is a parse error, it never runs the error_reporting() function in your PHP code.
Try this in a .htaccess file (assuming you can use one):
php_flag display_errors 1 php_value error_reporting 30719
I think 30719 corresponds to E_ALL but I may be wrong.
Edit Update: http://php.net/manual/en/errorfunc.constants.php
int error_reporting ([ int $level ] ) --- 32767 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0. 32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously
Adding to what deceze said above. This is a parse error, so in order to debug a parse error, create a new file in the root named debugSyntax.php. Put this in it:
<?php /////// SYNTAX ERROR CHECK //////////// error_reporting(E_ALL); ini_set('display_errors','On'); //replace "pageToTest.php" with the file path that you want to test. include('pageToTest.php'); ?>
Run the debugSyntax.php page and it will display parse errors from the page that you chose to test.
Just write a following code on top of PHP file:
I have had this problem when using PHP5.4 and Plesk 11.5
Somehow, the error reporting and display error settings in the Plesk domain configuration page were completely overriding any local settings in .htaccess or the PHP scripts. I have not found a way to prevent this happening, so use the Plesk settings to turn error reporting on and off.
You may have settings in your php.ini that prevents the local site from overriding these settings, perhaps enforced by the control panel used on your server.
To people using Codeigniter (i’m on C3):
The index.php file overwrite php.ini configuration, so on index.php file, line 68:
case 'development': error_reporting(-1); ini_set('display_errors', 1); break;
You can change this option to set what you need. Here’s the complete list:
1 E_ERROR 2 E_WARNING 4 E_PARSE 8 E_NOTICE 16 E_CORE_ERROR 32 E_CORE_WARNING 64 E_COMPILE_ERROR 128 E_COMPILE_WARNING 256 E_USER_ERROR 512 E_USER_WARNING 1024 E_USER_NOTICE 6143 E_ALL 2048 E_STRICT 4096 E_RECOVERABLE_ERROR
Hope it helps.