Enabling PHP error messages is essential for debugging your website, as it allows you to identify problems in your PHP code. By turning on PHP error reporting, you can see warnings, notices, and errors directly on your website, making it easier to troubleshoot issues.

This guide will show you how to turn on PHP error messages via cPanel using two methods:

  1. Enabling error reporting through MultiPHP INI Editor.
  2. Manually updating the php.ini file.

1. Enable PHP Error Messages Using MultiPHP INI Editor

The MultiPHP INI Editor in cPanel is a simple way to configure PHP settings, including error reporting.

Step-by-Step Instructions:

  1. Log in to cPanel
    • Go to your cPanel login URL (usually yourdomain.com/cpanel).
    • Enter your username and password.
  2. Access MultiPHP INI Editor
    • In the cPanel dashboard, scroll down to the Software section.
    • Click on MultiPHP INI Editor.
  3. Select Your Domain
    • On the MultiPHP INI Editor page, select the domain where you want to enable PHP error reporting from the dropdown menu.
  4. Edit PHP Settings
    • Once your domain is selected, you will see a list of configurable PHP directives. Look for the following settings:
      • display_errors: Set this to On. This will display errors on your website.
      • log_errors: Set this to On if you also want to log errors to a file for later review.
      • error_reporting: This determines the level of errors to be displayed. Use E_ALL to display all PHP errors, warnings, and notices.

Example settings:
makefile
Copy code
display_errors = On

log_errors = On

error_reporting = E_ALL

  1. Save Changes
    • Scroll to the bottom of the page and click Apply to save your changes.

2. Manually Enable PHP Error Messages by Editing php.ini

If you want more control over the PHP configuration, you can manually edit the php.ini file to enable error reporting.

Step-by-Step Instructions:

  1. Log in to cPanel
    • Access your cPanel dashboard.
  2. Access the File Manager
    • In the Files section, click on File Manager.
  3. Locate Your php.ini File
    • Navigate to the directory where your website is installed (e.g., /public_html).
    • Look for a file named php.ini. If you don’t see this file, you may need to create it.
  4. Edit the php.ini File
    • Right-click on php.ini and select Edit.

Add or update the following lines:
makefile
Copy code
display_errors = On

log_errors = On

error_reporting = E_ALL

  1. These directives enable the display of all error messages and ensure that they are logged.
  2. Save Changes
    • Click Save Changes after editing the file.

3. Enabling Error Reporting via .htaccess

If you don’t have access to the php.ini file or are using shared hosting, you can enable PHP error reporting via the .htaccess file.

Step-by-Step Instructions:

  1. Access the File Manager
    • In cPanel, go to File Manager and open the directory where your website’s .htaccess file is located (usually in /public_html).
  2. Edit the .htaccess File
    • Right-click the .htaccess file and select Edit.

Add the following lines to the file:
csharp
Copy code
php_flag display_errors on

php_value error_reporting E_ALL

  1. Save Changes
    • Save and close the .htaccess file.

4. Verify PHP Error Reporting is Enabled

To verify that PHP error reporting is working correctly, create a simple PHP file with an intentional error:

  1. Open File Manager and navigate to your website’s directory.
  2. Create a new PHP file, for example, test_error.php.

Add the following code:
php
Copy code
<?php

echo $undefined_variable;

?>

  1. Save the file and open it in your browser (yourdomain.com/test_error.php). If error reporting is enabled, you should see a notice or warning about the undefined variable.

5. Common PHP Error Reporting Levels

  • E_ERROR: Fatal runtime errors that cause script termination.
  • E_WARNING: Non-fatal runtime errors; execution continues.
  • E_PARSE: Compile-time errors, such as syntax mistakes.
  • E_NOTICE: Minor runtime errors, often involving undefined variables.
  • E_ALL: All errors, warnings, and notices (best for development environments).

Conclusion

Enabling PHP error messages in cPanel is an essential step for troubleshooting and debugging your website. Whether you use the MultiPHP INI Editor, manually edit the php.ini file, or modify the .htaccess file, turning on error reporting will help you identify and resolve issues more quickly.

Make sure to turn off display_errors in production environments to avoid exposing sensitive information to users. You can still keep log_errors enabled to review errors in the log files while keeping them hidden from the public.

Var dette svaret til hjelp? 0 brukere syntes dette svaret var til hjelp (0 Stemmer)