Ultimate Web Tips
your Wordpress, jQuery, PHP, MySQL, Linux and CSS guide to a successful website
Read more:

March 17th, 2011

How to enable PHP error logging via .htaccess

Apache, by Joakim Ling.

Logging PHP errors via .htaccessHere I will show you how to suppress PHP errors from visitors and enable logging to a file via htacecss

Tracking PHP errors is a must when troubleshooting unexpected issues, related to plugins, themes. But you don’t want to have them visible on your site, especially not your customers. Here is a tutorial how to log all PHP errors behind the scenes to a private file.

Hide PHP errors on your site

Open .htaccess in your webroot directory, add following lines

# remove php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off

Save your file and PHP errors will no longer be displayed publicly. keeps those ugly, misleading PHP errors from breaking your site layout and disorienting your visitors.

Store PHP errors to a private file

Now when we hidden all errors, we need to enable logging of PHP to be able to debug or troubleshoot.

First we need to start with creating a log file, goto your webroot directory and create an empty file called php_errors.log, set permissions to 755 (or 777)

Open your .htaccess file again and add the following line

# enable PHP error logging
php_flag  log_errors on
php_value error_log  /home/domain/public_html/php_errors.log
# stop access to the log
 
 Order allow,deny
 Deny from all

Test it and verify that logging works, if not try change permission of the php_errors.log file.

Setting up a web server

Learn how to configure a web server from home, read more

Back Top

Club World Casinos
  • http://www.kaltechsolutions.com Kaltech Solutions

    Errors must be logged to further research the channels from where they are coming from. enabling the error logging process via .htaccess is a good alternative.