PHP: Log errors to a logfile locally - php

I am trying to setup PHP to log errors locally so that I can solve this problem.
However, I can't even get this to work. I have followed this tutorial, but nothing. Does it only log fatal errors or what?
Is there anything else I need to make sure of?

need these settings:
log_errors = on
error_reporting = E_ALL
if you want to set these in .htaccess, you can do somn like:
php_value log_errors 1
php_value error_reporting 6143

Related

I can't disable PHP errors

So what's going on is I tried
ini_set('display_errors', 'Off');
error_reporting(0);
Right below <?php, but this didn't seem to stop displaying them. So I went to the php.ini and went to display_errors and saw that it was set to Off. But it still showed.
So I went and did phpinfo() and display_errors along with display_startup_errors are both off. Also html_errors is off. I'm not sure if this will help, but it says error_reporting is set to -10241. Any ideas?
Do not change the value of error reporting to solve the issue. If display_errors is off, errors are not display independently of the error_reporting setting. This way you will not display errors but you can still log them.
The following should work:
ini_set('display_errors', 'Off');
If it doesn't work it could be that your server configuration does not allow you to change settings from PHP scripts. ini_set() returns FALSE on failure. So first of all you should check what value that call is returning. Make sure that ini_set is not listed among disabled PHP functions (disable_functions in php.ini).
If you are asking yourself why errors are still being displayed even if in php.ini the display_errors is Off, you can check the actual value of display_errors during the script execution:
ini_get('display_errors')
Pemember that PHP settings could be changed also in Apache host configuration and in .htaccess files. So check if you have an htacces that enables display_errors. Something like this:
php_flag display_errors on
Try to use:
ini_set('display_errors', 0);
ini_set('display_errors', false);
You don't describe what the errors are, so it's possible that your web server (Apache, nginx, etc) are what's throwing the error and not PHP.
If it is PHP, ensure that you're editing the correct php.ini as identified in your phpinfo.php. Remember that if you edit the php.ini, you will need to restart your PHP process (for example, on some *nix systems: service php-fpm restart. Your exact command may vary.)
If it's off in your php.ini, my guess is that it's being overridden somewhere else -- either later in the script ('grep "ini_set" /path/to/project/*.php' will find it). Also, the PHP Manual states that if the script has fatal errors, it doesn't apply if there are fatal errors:
Although display_errors may be set at runtime (with ini_set()), it
won't have any effect if the script has fatal errors. This is because
the desired runtime action does not get executed.

Why isn't PHP displaying errors under IIS7?

I get a blank white page when running a script that I'm migrating from a Linux Apache server to IIS.
Following advice elsewhere on SO, I checked that the correct php.ini is being loaded. From phpinfo():
Loaded Configuration File C:\php\php.ini
In that php.ini file, I have the following:
error_reporting = E_ALL
display_errors = On
log_errors = On
error_log = "C:\Windows\Temp\php_errors.log"
For good measure, I have also added
ini_set( 'display_errors', 1 );
error_reporting(E_ALL);
in the script itself.
I'm getting no errors output to the screen, and the file C:\Windows\Temp\php_errors.log doesn't exist.
I'm obviously missing something; what is it? :)

why do I see the output of error_log but not die in PHP?

I noticed that when I issue a die statement in php, it's output doesn't appear on the error log (If i put an error_log statement right beside it it shows fine though).
I tried everything.. Here are the settings I did to make sure I see all my error logs:
php.ini:
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
error_log = /Applications/XAMPP/logs/error_log
httpd.conf:
php_value error_log /Applications/XAMPP/logs/error_log
i even set up an .htaccess file in the root directory of one of my virtual hosts:
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_value error_log /Applications/XAMPP/logs/error_log
but then every time I reach a statement like this in the code:
die("I love Prestashop");
the code just dies without any output.. any ideas guys?
I got the site running on my localhost using XAMPP and I'm running a Prestashop website, with PHP 5.3.1
Calling die() should not produce output in the error_log as calling it is not an error.
It is just a PHP construct (alias to exit()) that exits the current script and sends (optional) output (or an error code that is useful when used in a CLI environment).
die() or exit() is not useful for reporting errors. They cannot be caught and cannot be logged. Use trigger_error() instead.

Displaying Errors in PHP

I have php v5.3.2 on ubuntu 10.04. i changed the reporting options in /etc/php5/apache2/php.ini to these:
display_errors = 1
error_reporting = E_ALL
I also added these lines to the top of my php files and restarted apache but im still not able to see the errors/warnings,
ini_set('display_errors',1);
error_reporting(E_ALL);
Is there anything else in the way that prevents the errors from showing up?
Edit 1: According to phpinfo(), both display_errors and display_startup_errors are on.
The value of error_reporting is also 30719 which i'm not quite sure what it means.
Could you try error_reporting(-1); ?

PHP won't show any errors

Here is my code:
echo 'foo';
error_reporting(E_ALL);
echo 'this line doesnt end in a semi colon'
echo 'i should get an error here';
When I run this I get no error.
Not sure how this can be?
ini_set('display_errors', 1);
Do note though that if you do this in the file that has the syntax error, it won't work, as it'll never get executed then. You can also set this true in php.ini (not recommended for production servers), or if you use Apache, in .htaccess with:
php_flag display_errors 1
error_reporting directive won't help you to show error messages on-screen. It's responsible for which error to show, not where.
if your PHP runs as Apache module (most likely it does) add the following line into .htaccess file:
php_value display_errors 1
when you switch to production, change it to
php_value display_errors 0
php_value log_errors 1
and watch them it in the error log.
Do you have any kind of shutdown hooks, error-handling functions or global exception catchers running?
Syntax errors can be quirky in large frameworks :)

Categories