Enabling error display in PHP via htaccess only
.htaccess:
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 /home/path/public_html/domain/PHP_errors.log
How can I display PHP errors through htaccess
You can use these commands to enable error reporting and set the error level using your .htaccess file.
php_flag display_errors on
php_value error_reporting <error level>
You can also define error reporting in some kind of php config file using error_reporting().
error_reporting(E_ALL);
How can I disable notices and warnings in PHP within the .htaccess file?
It is probably not the best thing to do. You need to at least check out your PHP error log for things going wrong ;)
# PHP error handling for development servers
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0
Enable display_errors in .htaccess using `php-fpm` execution mode?
When using fpm PHP scans for a ini file in each directory
http://php.net/manual/en/configuration.file.per-user.php
Default is .user.ini
You should be able to put the same config in there but with the same syntax as php.ini:
display_errors = On
display_startup_errors = On
html_errors = 1
error_reporting = -1
PHP error handling with .htaccess & writing into php_error.log text file
Please try to do the following:
In .htaccess
# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_value docref_root 0
php_value docref_ext 0
# enable PHP error logging
php_flag log_errors on
php_value error_log /correct_path_to_your_website/error_modes/PHP_errors.log
# general directive for setting php error level
php_value error_reporting -1
In php file
Instead of intentional mistake in you wrote in your php file you can try doing something like:
<?
echo $_SERVER['DOCUMENT_ROOT']; // this will enable you to see
// the correct path to your website dir
// which should be written in .htaccess
// instead of correct_path_to_your_website
// (check it just in case)
$foo = $bar['nope'];// this should generate notice
call_undefined(); // this should generate fatal error
?>
Worked good with me)
Hope it'll help.
How do I get PHP errors to display?
This always works for me:
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
However, this doesn't make PHP to show parse errors - the only way to show those errors is to modify your php.ini with this line:
display_errors = on
(if you don't have access to php.ini
, then putting this line in .htaccess
might work too):
php_flag display_errors 1
How can I turn on PHP errors display on just a subfolder
In .htaccess
:
php_value error_reporting 2147483647
This number, according to documentation should enable 'all' errors irrespective of version, if you want a more granular setting, manually OR the values together, or run
php -r 'echo E_ALL | E_STRICT ;'
to let php compute the value for you.
You need
AllowOverride All
in apaches master configuration to enable .htaccess files.
More Reading on this can be found here:
- Php/Error Reporting Flag
- Php/Error Reporting values
- Php/Different Ways of Tuning Settings
Notice If you are using Php-CGI instead of mod_php, this may not work as advertised, and all you will get is an internal server error, and you will be left without much option other than enabling it either site-wide on a per-script basis with
error_reporting( E_ALL | E_STRICT );
or similar constructs before the error occurs.
My advice is to disable displaying errors to the user, and utilize heavily php's error_log feature.
display_errors = 0
error_logging = E_ALL | E_STRICT
error_log = /var/log/php
If you have problems with this being too noisy, this is not a sign you need to just take error reporting off selectively, this is a sign somebody should fix the code.
@Roger
Yes, you can use it in a <
construct in apaches configuration too, however, the .htaccess in this case is equivalent, and makes it more portable especially if you have multiple working checkout copies of the same codebase and you want to distribute this change to all of them.Directory>
If you have multiple virtual hosts, you'll want the construct in the respective virtual hosts definition, otherwise, yes
<Directory /path/to/wherever/on/filesystem>
<IfModule mod_php5.c>
php_value error_reporting 214748364
</IfModule>
</Directory>
The Additional "ifmodule" commands are just a safety net so the above problem with apache dying if you don't have mod_php won't occur.
Related Topics
What Type of Hash Does Wordpress Use
Passing JavaScript Array to PHP Through Jquery $.Ajax
Continue PHP Execution After Sending Http Response
Mixing a PHP Variable With a String Literal
What Are Register_Globals in PHP
Does File_Get_Contents() Have a Timeout Setting
PHP Pdo: Get the Columns Name of a Table
Manipulate a String That Is 30 Million Characters Long
PHP Class Instantiation. to Use or Not to Use the Parentheses
PHP Mail() Function on Localhost
.Htaccess Rewrite Get Variables
How to Require a Fork With Composer
PHP: How to Remove Specific Element from an Array