PHP Error Handling using ini_set or .htaccess

Tracking your site’s PHP errors is an excellent way to manage and troubleshoot unexpected issues related to plugins and themes. While there is no definitive method for handling errors, there are some "best practices" that should be implemented in all PHP applications.

An "error" is an expected or unexpected event that occurs when your PHP code is running. An "expected" error can be a database query that returns no result or an html form that is missing values for designated required fields. An "unexpected" error is one that assumes a particular application state which, for some as yet unknown reason, does not exist. The most obvious unexpected error is a database that is not running or a missing file that one of your scripts expects to find.

Configuration settings for PHP Error handling and reporting are available in php.ini file, which is located in the PHP installation folder of your system. For reference, settings of any PHP configuration can be changed in various ways – using ini_set(), in WINDOWS registry, in php.ini, in .htaccess or in httpd.conf. PHP_INI_ALL indicates that the related configuration can be changed in any the aforementioned ways.

Using PHP to Manage PHP Error Reporting

Enabling Error Reporting in PHP is quite simple. At the top of your script place the following lines of code. This is by far the easiest method and will work in most hosting environments:

ini_set('display_errors', true);

Using ini_set we defined the value of a configuration option from the PHP.ini file. There is also a list of all directives you can set to configure your PHP setup on the manual.

Using .htaccess to Manage PHP Error Reporting

An alternative method would be a technique whereby PHP errors are suppressed via htaccess. This is accomplished by including the following htaccess directives to your domain’s httpd.conf or to your site’s root (or other target directory) htaccess file:

# hide php errors
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 error_reporting -1
php_value log_errors_max_len 0
Order allow,deny
Deny from all
Satisfy All


In this tutorial, I’ve hopefully covered the most common techniques for handling failures within PHP applications.

16 thoughts on “PHP Error Handling using ini_set or .htaccess

  1. support to microosft
    support to microsoft toll free
    support to microsoft toll free Number
    support for microsoft
    support to ms office
    support to windows xp
    support to windows vista
    support to windows 7
    Microsoft support number
    microsoft technical support number
    microsoft support tollfree number
    microsoft customer tollfree number
    microsoft service tollfree number
    microsoft support
    microsoft online help
    microsoft tech help
    microsoft helpline number

  2. There were quite a few aspects that Apple missed out when they launched iOS 10, so people are quite naturally expecting a lot

    from Apple this time arond when the launch date of iOS 11 is fast approaching. So if you are an Apple fan and love the

    flagship devices of Apple, then you must be interested to know more about iOS 11, its probable features, the devices that will

    support it and obviously the launch date. Well you have to look no further as I have all the information you need right at

    your fingertips. Just take a look here iOS 11 download

  3. Hello .. When I am on your site, I have to say that your website is really good, I love to read the content, its outstanding! I’m in a bit of a hurry in this case to completely read your blog, but I’ve encouraged it. I come back when I have some time off. Bravo for a great site. Find Out More

  4. We are just few days away from the iOS 12 beta download release for developers. Apple has prepared everything for the developers only launch event. You can download iOS 12 beta for your iPhone and iPad device using our services.

  5. I loved the post, keep posting interesting posts. I will be a regular reader. am totally agree with the above mentioned topic. I think, this post should be shared as much as possible.

Leave a Reply

Your email address will not be published. Required fields are marked *