Skip to content

Displaying PHP errors in web hosting

Displaying and logging PHP errors can be enabled by adding settings to the .htaccess file. This helps during website development and when troubleshooting issues.

Saving errormessages to a log-file:

1. Edit the .htaccess file

Open your website’s .htaccess file. It is usually located in the root directory of your website, for example:
/home/u12345/public_html

2. Add the following settings to the .htaccess file

# log errors to a file
php_flag log_errors 1
php_value error_log /home/u12345/test/errors.log

# display errors on the page
php_value display_errors 1

# error reporting level (-1 = all errors)
php_value error_reporting -1

What these settings do

log_errors 1
Enables logging of PHP errors.

error_log /home/u12345/test/errors.log
Specifies the file where errors will be stored. In this example, errors are saved to errors.log.

display_errors 1
Displays errors directly on the web page. This is useful during development, but it is generally not recommended in a production environment.

error_reporting -1
Defines the error reporting level. The value -1 means that all PHP errors and warnings will be reported.

Was this article helpful?