If your website uses PHP and it's not working as expected, displaying PHP error messages can help you efficiently identify and fix any potential issues within the code.
There are a few alternative methods you can choose from to display and log error messages. Check the detailed steps below:
Option 1 – Error Display and Logging
You have two settings available on hPanel regarding information about PHP errors:
To display them on the website directly
To store them in a log file
To enable either or both of them, go to Websites → Manage, search for PHP Configuration on the sidebar and click on it:
Once there, head to the PHP options tab and check the corresponding boxes:
To make errors visible on your website directly, enable the displayErrors (display_errors) parameter
To log a record of the errors to a file, mark the logErrors (log_errors) checkbox:
Scroll down to the bottom of the page and click on Save to apply the changes.
Option 2 – Display Errors on WordPress
If you are using WordPress, go to the File Manager and open your public_html/wp-config.php file. Then, search for the debugging line:
If the line exists, change the value from false to true. Then, add the following line to enable error display on your website:
That's it – now the PHP errors, if any, will be displayed directly on your WordPress website.
Option 3 – Display and Log Errors via the .htaccess File
You can log the PHP errors to a log file of your choice using the .htaccess file. First, create a backup of the .htaccess file before making any changes, as incorrect settings can make your website inaccessible. Or, if there is no .htaccess file, you can create it.
Next, add the following lines to your website's .htaccess file:
# log PHP errors to a file
php_flag log_errors on
php_value error_reporting 32767
php_value error_log "error_log.txt"
Displaying and logging errors with any of these methods will help you troubleshoot your PHP code. If you require further help to solve the causes behind any error, you can seek the assistance of a developer.
Once you are done working with the error data, it is recommended to hide it again to prevent potentially sensitive information from being exposed to users and protect against security risks