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 |
- The first line will let the error messages to display in the browser.
- The first line can’t enable displaying PHP’s startup sequence errors. To display those errors, the second line is required.
- When an error message is displayed in the browser, parts of that are marked as bold. Well, HTML tags are responsible for those. You can check those tags in the browser’s view source. The third line above is used to add HTML tags in the error messages. Changing to off will show just plain error messages.
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.
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?