Skip to content

Debugging Drupal Code

Debugging PHP can be a game changer in Drupal development. In the context of L3D in combination with the composer plugin Docker4Drupal this is provided out of the box and configured very easily. We describe the steps for PhpStorm, but other IDEs should be very similar.

As XDebug comes with a performance hit, it is turned off by default. When you need it, simply call ahoy debug on in you L3D container of the project you want to debug and the scripts will reconfigure the PHP container and refresh it with a few seconds. When you've finished debugging, you may want to turn it off again with ahoy debug off.

XDebug version 3 connects to port 9003 of your IDE and PhpStorm is preconfigured by default to list on that port.

Add a PHP Server

First, you have to set up a Drupal environment with the tool l3d. The tool is based on Docker containers.

Now navigate to File->Settings in your IDE and create a server:

Screenshot

Set the following values:

Screenshot

Important: Always use Docker as name of your server.

Do not forget to add the file mapping to /var/www/html.

Add a new Run/Debug Configuration

Screenshot

First create a new PHP Web Page configuration:

Screenshot

Set the following values:

Screenshot

Select the server you just have created.

Important: Always use Docker as name of your configuration.

Start Debugging

First, check the debug settings in your IDE. It should look something like this:

Screenshot

Now activate the Phone icon in your IDE:

Screenshot

Now you can set your breakpoints and enjoy debugging Drupal code.