Enabling error display in PHP via htaccess only
Asked Answered
M

5

119

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

Mundt answered 25/5, 2011 at 16:50 Comment(3)
i have done some googling, added some flags to my htaccess; and my pages cannot display againMundt
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.Jarad
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.Louie
D
200

.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
Donovan answered 25/5, 2011 at 16:54 Comment(9)
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 errorMundt
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. php.net/manual/en/configuration.changes.phpDonovan
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.Ceasar
like ogugua I also now have internal server error by using these lines.Dennet
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.Radioactive
"Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration, referer: .htaccess file-path"Radioactive
If you get a 500 it's probably because you're using php-fpm, not mod_php.Cavernous
How can we make it work for php-fpm execution mode?Pennsylvania
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)?Hillegass
A
43
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.

Anacreontic answered 25/5, 2011 at 16:57 Comment(1)
I use this website to calculate the integet value easier: maximivanov.github.io/php-error-reporting-calculatorStillman
C
21

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

Casimiracasimire answered 8/1, 2016 at 9:56 Comment(1)
how about giving chmod "0644" to the error log file? would it be working still?Vulpecula
U
4

If you want to see only fatal runtime errors:

php_value display_errors on
php_value error_reporting 4
Upstart answered 23/8, 2017 at 23:28 Comment(0)
B
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>
Buber answered 15/8, 2019 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.