Want to log PHP Errors with .htaccess in production and development env?

Published by Subhas Fagu on 25/04/09 22:56:23
Last edited on 06/05/09 18:34:06

This is another article of the great .htaccess file. In this article you will find two scripts with appropriate comments to help you easily customize your PHP error log file. There is a production edition which silences all errors and then there is a development edition which shows all errors in real time as thy occur in addition to the log file.

Below is a production edition which is ideal for a site that is active, live, etc. This edition will make sure that no errors are ever displayed on the live site but instead written to a specified log file.

.htaccess file: Production Edition

# disable display of startup errors
php_flag display_startup_errors off
# disable display of all other errors
php_flag display_errors off
# disable html markup of errors
php_flag html_errors off
# enable logging of errors
php_flag log_errors on
# disable ignoring of repeat errors
php_flag ignore_repeated_errors off
# disable ignoring of unique source errors
php_flag ignore_repeated_source off
# enable logging of php memory leaks
php_flag report_memleaks on
# preserve most recent error via php_errormsg
php_flag track_errors on
# disable formatting of error reference links
php_value docref_root 0
# disable formatting of error reference links
php_value docref_ext 0
# specify path to php error log
php_value error_log /home/path/public_html/domain/PHP_errors.log
# specify recording of all php errors
php_value error_reporting 999999999
# disable max error string length
php_value log_errors_max_len 0
# protect error log by preventing public access
<files >
Order allow,deny
Deny from all
Satisfy All
</files>

Below is the development edition, this setup is ideal for sites that are not yet published to the public. This setup is ideal as it will catch & display errors in real time.

.htaccess file: Development Edition


# PHP error handling for production servers
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
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 999999999
php_value log_errors_max_len 0
<files >
Order allow,deny
Deny from all
Satisfy All
</files>

About the Author

Subhas Fagu is an energetic person who you will never catch doing the same thing twice…unless it’s working. He’s always engaged in new concepts, frameworks, operating systems, applications, you name it and you’ve got a conversation. Being a founder of Techlicity Ventures, he's been a key in the business and technical development of all previous and upcoming projects. Subhas contributes a wide variety of perspectives to all projects to ensure risk coverage and smooth deployment.

Bookmark and Share
Blog Widget by LinkWithin
blog comments powered by Disqus

Valid XHTML 1.0!