How to Enable PHP Error Reporting Using .htaccess File?

Problem:

You know you’ve errors in your script, but are not displaying in the browser. You may have not access in the php.ini file to enable displaying those errors. But, you can edit the .htaccess file. So, you’re looking for the solution of showing error messages using .htaccess file.

Solution:

Please follow the steps below to enable php error messaging using .htaccess file.

Step 1: Enable errors to display

Add the following lines in the .htaccess file to enable displaying error messages.

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

Step 2: Log error messages in log file (optional)

  • If you want to save errors in the error log file of the server, add the following line in the .htaccess file. Replacing with “of” instead of “on” at last will not save error in the log file.
    php_flag log_errors on
  • You can also set the error log file’s location in the .htaccess file. For example, in the following, I saved the log file in the F:\ drive.
    php_value error_log F:\xampp\php\logs\php_error_log

    Make sure that the file has write permission.

In the production level, you must turn of all the commands in mentioned in step 1 to show any error to the users. But, keeping the log_errors option on (step 2) will ensure saving those errors in the log file.

All in One

So, All you need is the following lines to enable displaying error message. Paste these lines in your .htaccess file-

php_flag display_startup_errors onphp_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_value error_log F:\xampp\php\logs\php_error_log

There are other methods to accomplish the same task. Check the following-
How to Enable PHP Error Reporting Using php.ini?