How to Display and Log PHP Errors Using .htaccess?

Barbara Streisand
Release: 2024-11-02 11:37:30
Original
549 people have browsed it

How to Display and Log PHP Errors Using .htaccess?

Displaying PHP Errors with .htaccess

To debug PHP issues on a live website with limited access to configuration files, utilizing .htaccess can be a helpful solution. By adding the following code to your .htaccess file, you can enable error display without modifying the php.ini file:

php_flag display_errors on
php_flag display_startup_errors on
php_flag html_errors on
Copy after login

However, this approach only displays errors on the webpage, which may be impractical for sensitive websites. To capture errors in a log file for later analysis, add the following lines to .htaccess:

php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
Copy after login

The error_log directive specifies the path to a log file where PHP errors will be recorded. You should replace "/home/path/public_html/domain/PHP_errors.log" with the actual location on your server.

With these settings in place, PHP errors will be displayed both on the webpage and logged to the specified file. This allows you to diagnose issues promptly while maintaining the user-friendliness of your website.

The above is the detailed content of How to Display and Log PHP Errors Using .htaccess?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!