Categories: Drupal

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.

Article by: Web Designers Near Me | Author: Joseph Cozens – Senior Website Designer

With over 25 years experience, Joseph started as the leased line manager for an ISP in the 1990’s and built websites for the support team internally, but was often asked by corporate business customers if we could provide a website for their company. So in 1998 with people looking for website designers near me, he started the web design company building websites part time, and in 1999 started building websites full time. In the early 2000’s we decided to call ourselves DesignsOnline.co.uk Joseph built one of the first online medical schools allowing doctors worldwide to enrol and pay for medical statistics training via the internet… Joseph used to build bespoke content management systems for companies who needed to regularly update their websites and for bespoke ecommerce websites which were hand coded at the time.

Today Joseph develops and builds top level professional websites without the needlessly high price tag.
You can contact Joseph directly via WhatsApp on 07944062954.

Web Designers Near Me

With over 25 years experience, Joseph started as the leased line manager for an ISP in the 1990's and built websites for the support team internally, but was often asked by corporate business customers if we could provide a website for their company. So in 1998 with people looking for website designers near me, he started the web design company building websites part time, and in 1999 started building websites full time. In the early 2000's Joseph built one of the first online medical schools allow doctors worldwide to enrol and pay for medical statistics training via the internet.