RSS

How to show PHP errors in your website scripts using .htaccess

25 Apr

Most web servers are configured to disable the display of php errors on every website for security reasons. This means, whenever you upload a PHP script that contains errors you will be greeted with a rather useless blank page.

There are a number of elegant solutions you can use to resolve this problem. One, for example, is adding display_errors to the top of your PHP file that contains errors.

But I am too lazy to deal with that on a script-by-script basis. What I prefer to do is create an .htaccess file on the site I am working that is configured to spit out every PHP error that occurs in every script on my site.

All that’s needed is to paste the following two lines to the top of a .htaccess file in the web root directory of your website:

php_flag display_errors on
php_value error_reporting 8191

It’s important to remember to disable these errors when you have finished working on your site. I do this by simply hashing out the two lines in the top of my .htaccess file as follows:

# php_flag display_errors on
# php_value error_reporting 8191

Now whenever I need to look at PHP errors again, I simply remove the hashes and the information is presented to me.

It should be noted the information revealed in these errors can contain information that can be potentially useful to hackers and crackers. So you should really only be enabling these errors on a password protected website.

About these ads
 
Leave a comment

Posted by on April 25, 2010 in Web Development

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: