Xdebug can be used to debug both web requests as well as cli scripts (e.g., Drush commands).
Xdebug integration is disabled by default as it causes a roughly 20% performance hit. To enable it:
fin config set --env=local XDEBUG_ENABLED=1
fin project start
To verify that Xdebug was enabled:
$ fin exec php -v | grep -i xdebug
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
Next, follow the IDE specific setup steps:
First, follow the setup instructions to enable the Xdebug integration.
PHPStorm makes debugging setup very easy using the Incoming Connection Dialog.
Click on the Start Listening for PHP Debug Connections button in PHPStorm
Open the project in a browser
A debugging session will start and Xdebug will initialize a connection to PHPStorm.
Click on Accept in the Incoming Connection From Xdebug dialogue in PHPStorm
PHPStorm automatically configures a server and directory mappings between the host and the server.
Directory mappings are very important, as that’s how PHPStorm knows how to map sources on the server to those on
the host. By default, you will not be able to debug anything above the project’s docroot
folder.
If you don’t get the Incoming Connection From Xdebug dialogue or you need to debug scripts above the docroot
directory, see the manual setup steps.
myproject.docksal
)Configure host to server directory mappings
Map the project directory on the host to /var/www/
on the server:
With this manual setup you will be able to debug scripts within your project’s root (/var/www/
on the server).
First, follow automatic or manual instructions to configure server and path mapping settings in PHPStorm.
To debug PHP CLI scripts, we have to tell PHPStorm which existing server configuration to use via the
PHP_IDE_CONFIG
variable. This can be done using the following commands:
fin config set --env=local 'PHP_IDE_CONFIG=serverName=${VIRTUAL_HOST}'
fin project start
The script you are trying to debug must reside within the project root directory (/var/www/
on the server) or
PHPStorm won’t be able to access the scripts’s source code and debug it.
To debug custom Drush commands, make the following additional adjustments in PHPStorm settings:
Uncheck Force break at the first line when a script is outside the project
You can run your scripts in console and debug them in the same way as browser requests. For example, you can run
fin drush fl
and debug this Drush command from the Features module.
Configure PHP Debug Settings
PHP
from the dropdown listpathMappings
Here is an an example of what launch.json
should look like:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/": "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"pathMappings": {
"/var/www/": "${workspaceFolder}"
}
}
]
}
Set a breakpoint
Select the Listen for XDebug configuration from the dropdown and click Start Debugging
You can debug both web requests and cli scripts using this configuration.
To debug Drush commands using Xdebug and VSCode, add the following to your path mappings under the configuration that begins with "name": "Listen for XDebug",
Drush 8.x
"/usr/local/bin/drush": "${workspaceFolder}/bin/drush"
to pathMappings
in your launch.json
file.Drush 9.x
"/usr/local/bin/drush": "${workspaceFolder}/vendor/bin/drush"
to pathMappings
in your launch.json
file.Configure project properties:
docroot
)myproject.docksal
) to set the Project URLSet a breakpoint wherever you like
In NetBeans, with the whole project selected or one of the project files opened and active, press <CTRL> + <F5>
on your keyboard to start the debugger
Configure PHP Debug Settings (Preferences > Packages)
*