Debugging with Xdebug

Setting Up Xdebug with DDEV and VS Code

For this video, we are going to learn how to set up Xdebug with VS Code running a local server on DDEV.

For this video, we are going to learn how to set up Xde­bug with VS Code run­ning a local serv­er on DDEV. Xde­bug runs on the serv­er, as a PHP exten­sion, so the first thing we need to do is enable Xde­bug in our Dock­er con­tain­er that is man­aged by DDEV.

For­tu­nate­ly, DDEV already has sup­port for this and a com­mand we can to tog­gle Xde­bug on and off. This is how we can set whether we are in debug mode or not.

$ ddev xdebug enable

This enables Xde­bug so it is run­ning as a PHP exten­sion. Now it will be avail­able to call back to our IDE on port 9003 when it receives a HTTP request.

The launch.json con­fig­u­ra­tion file for DDEV and VS Code:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "hostname": "yourhostname.ddev.site",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceRoot}"
            }
        }
    ]
}

Debugging with Xdebug is made up of the following videos: