
How to debug in Drupal 9
To debug your Drupal 9 website, you can follow these steps:
Step 1: Enable Debugging
In your Drupal 9 website, open the `settings.php` file located in the `sites/default` directory. Look for the line that sets the `$config[‘system.logging’][‘error_level’]` value.
Change the value to `verbose` to enable verbose error messages and debugging information. The line should look like this:
“`php
$config[‘system.logging’][‘error_level’] = ‘verbose’;
“`
Save the changes to the `settings.php` file.
Step 2: Clear the Cache
Clear the Drupal cache to ensure that the new debug settings take effect. You can clear the cache by running the following Drush command or using the administration interface:
“`shell
drush cache:rebuild
“`
Step 3: Enable Twig Debugging (optional)
If you are using Twig as the template engine in your Drupal 9 website, you can enable Twig debugging to get more detailed information about templates.
In the `settings.php` file, add the following line:
“`php
$config[‘twig.config’][‘debug’] = true;
“`
Save the changes to the `settings.php` file and clear the cache again.
Step 4: Display Errors and Warnings
To ensure that errors and warnings are displayed on the screen, you need to modify the PHP settings in your development environment.
Open the `php.ini` file and look for the following lines:
“`ini
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
“`
Change `display_errors` to `On` and `error_reporting` to `E_ALL`. Save the changes to the `php.ini` file.
Step 5: Use Devel Module (optional)
If you have the Devel module installed, you can use its debugging features to assist you in troubleshooting.
Install the Devel module by running the following command:
“`shell
composer require drupal/devel
“`
Once installed, you can enable the module using the administration interface or Drush:
“`shell
drush pm-enable devel
“`
The Devel module provides useful functions like `dsm()`, `dpm()`, and `kint()` to print debugging information to the screen or log it to a file.
Step 6: Debugging Tools
Drupal 9 provides several helpful tools for debugging. Some commonly used ones are:
– Use `var_dump()` or `print_r()` to print variables and their values for debugging purposes.
– Use the browser’s Developer Tools to inspect network requests, console messages, and JavaScript errors.
– Check the Drupal error logs located in the `sites/default/files` directory for detailed error information.
– Utilize the Drupal watchdog system to log custom debugging messages using functions like `watchdog()` or `Drupal::logger()`.
Remember to disable debugging and revert the changes made to the settings when you are done troubleshooting and deploying your Drupal 9 website to a production environment.
By following these steps and utilising the available debugging tools, you can effectively identify and resolve issues in your Drupal 9 website.

Need help? - Get a Quote in under a minute

Stephanie & Joseph are Award Winning London Web Designers at The UK Web Design Company who are ready to help you with your website today.
Just take a couple of seconds to fill out this quick easy form and we will contact you right back
Need help? - Get a Quote in under a minute from the best web designers near you

How to debug in Drupal 9
To debug your Drupal 9 website, you can follow these steps:
Step 1: Enable Debugging
In your Drupal 9 website, open the `settings.php` file located in the `sites/default` directory. Look for the line that sets the `$config[‘system.logging’][‘error_level’]` value.
Change the value to `verbose` to enable verbose error messages and debugging information. The line should look like this:
“`php
$config[‘system.logging’][‘error_level’] = ‘verbose’;
“`
Save the changes to the `settings.php` file.
Step 2: Clear the Cache
Clear the Drupal cache to ensure that the new debug settings take effect. You can clear the cache by running the following Drush command or using the administration interface:
“`shell
drush cache:rebuild
“`
Step 3: Enable Twig Debugging (optional)
If you are using Twig as the template engine in your Drupal 9 website, you can enable Twig debugging to get more detailed information about templates.
In the `settings.php` file, add the following line:
“`php
$config[‘twig.config’][‘debug’] = true;
“`
Save the changes to the `settings.php` file and clear the cache again.
Step 4: Display Errors and Warnings
To ensure that errors and warnings are displayed on the screen, you need to modify the PHP settings in your development environment.
Open the `php.ini` file and look for the following lines:
“`ini
display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
“`
Change `display_errors` to `On` and `error_reporting` to `E_ALL`. Save the changes to the `php.ini` file.
Step 5: Use Devel Module (optional)
If you have the Devel module installed, you can use its debugging features to assist you in troubleshooting.
Install the Devel module by running the following command:
“`shell
composer require drupal/devel
“`
Once installed, you can enable the module using the administration interface or Drush:
“`shell
drush pm-enable devel
“`
The Devel module provides useful functions like `dsm()`, `dpm()`, and `kint()` to print debugging information to the screen or log it to a file.
Step 6: Debugging Tools
Drupal 9 provides several helpful tools for debugging. Some commonly used ones are:
– Use `var_dump()` or `print_r()` to print variables and their values for debugging purposes.
– Use the browser’s Developer Tools to inspect network requests, console messages, and JavaScript errors.
– Check the Drupal error logs located in the `sites/default/files` directory for detailed error information.
– Utilize the Drupal watchdog system to log custom debugging messages using functions like `watchdog()` or `Drupal::logger()`.
Remember to disable debugging and revert the changes made to the settings when you are done troubleshooting and deploying your Drupal 9 website to a production environment.
By following these steps and utilising the available debugging tools, you can effectively identify and resolve issues in your Drupal 9 website.
Need help? - Get a Quote in under a minute
Need help? - Get a Quote in under a minute

Stephanie & Joseph Award Winning London Web Designers at
The UK Web Design Company are ready to help you with your website
Just take a couple of seconds to fill out this quick easy form and we will contact you right back
Need help? - Get a Quote in under a minute from the best web designers near you






