116

I am testing a website online.

Right now, the errors are not being displayed (but I know they exist).

I have access to only the .htaccess file.

How do I make all errors to display using my .htaccess file?


I added these lines to my .htaccess file:

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

And the pages now display:

Internal server error

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Ogugua Belonwu
  • 2,051
  • 6
  • 26
  • 44
  • i have done some googling, added some flags to my htaccess; and my pages cannot display again – Ogugua Belonwu May 25 '11 at 17:01
  • 3
    Seems like you don't have the rights to override these settings from htaccess. You might need to set `AllowOverride All` in the Apache config, if you have access to that. – kapa May 25 '11 at 17:03
  • Check your apache error log. It'll have to exact reason why you're getting the 500 internal error. What you see in the browser is by design useless for diagnostic purposes. – Marc B May 25 '11 at 17:13

5 Answers5

195

.htaccess:

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log
silex
  • 4,175
  • 4
  • 20
  • 27
  • 14
    i added these lines to my htaccess: php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on and the pages show internal server error – Ogugua Belonwu May 25 '11 at 16:58
  • 4
    When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files (e.g. httpd.conf) and .htaccess files. You will need "AllowOverride Options" or "AllowOverride All" privileges to do so. http://php.net/manual/en/configuration.changes.php – silex May 25 '11 at 17:01
  • Create the PHP_errors.log and make it 777 other way you probably wont see the file created by apache and filled... at least I had to create it. – PJunior May 03 '14 at 12:11
  • 2
    like ogugua I also now have internal server error by using these lines. – landed Mar 02 '15 at 12:55
  • Any update to this problem? Anyone found a solution? My htaccess file worked a few months ago, I only recieve 500 Internal Server Error now. – saltcracker Mar 11 '16 at 13:57
  • "Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration, referer: *.htaccess file-path*" – saltcracker Mar 11 '16 at 14:03
  • 1
    If you get a 500 it's probably because you're using php-fpm, not mod_php. – mpchadwick Jan 30 '18 at 02:13
  • How can we make it work for `php-fpm` execution mode? – cronoklee Nov 09 '18 at 13:12
  • Perhaps update for the updated question (9 minutes later back in 2011)? Why would the two log lines make a difference for the server error (probably not (some other reason?), but this could be explained)? – Peter Mortensen Apr 22 '20 at 13:32
42
php_flag display_errors on

To turn the actual display of errors on.

To set the types of errors you are displaying, you will need to use:

php_value error_reporting <integer>

Combined with the integer values from this page: http://php.net/manual/en/errorfunc.constants.php

Note if you use -1 for your integer, it will show all errors, and be future proof when they add in new types of errors.

Mukesh Chapagain
  • 22,983
  • 12
  • 108
  • 114
UFTimmy
  • 579
  • 3
  • 4
18

I feel like adding more details to the existing answer:

# PHP error handling for development 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 /full/path/to/file/php_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0

Give 777 or 755 permission to the log file and then add the code

<Files php_errors.log>
     Order allow,deny
     Deny from all
     Satisfy All
</Files>

at the end of .htaccess. This will protect your log file.

These options are suited for a development server. For a production server you should not display any error to the end user. So change the display flags to off.

For more information, follow this link: Advanced PHP Error Handling via htaccess

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Ashish
  • 539
  • 6
  • 18
3

If you want to see only fatal runtime errors:

php_value display_errors on
php_value error_reporting 4
Zeke
  • 382
  • 2
  • 11
2

This works for me (reference):

# PHP error handling for production servers
# 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
# [see footnote 3] # php_value error_reporting 999999999
php_value error_reporting -1

# Disable max error string length
php_value log_errors_max_len 0

# Protect error log by preventing public access
<Files PHP_errors.log>
 Order allow,deny
 Deny from all
 Satisfy All
</Files>
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Darkcoder
  • 636
  • 7
  • 15