Skip to content

Instantly share code, notes, and snippets.

@avblink
Last active February 18, 2021 19:34
Show Gist options
  • Save avblink/2add2f6490dab049400f1bd7f839cc01 to your computer and use it in GitHub Desktop.
Save avblink/2add2f6490dab049400f1bd7f839cc01 to your computer and use it in GitHub Desktop.

xDebug, WSL2, Docker

Some useful commands to get xdebug running with docker on wsl2

xdebig.ini configuration:

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.idekey = VSCODE

; "hostname": "0.0.0.0" // add this in your vscode launch.json if xdebug.remote_host = host.docker.internal
xdebug.remote_host = host.docker.internal
xdebug.remote_connect_back = 0

xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_enable = 1

xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.remote_log=/var/log/php/xdebug.log

VSCode launch.json:

{
   "version": "0.2.0",
   "configurations": [
       {
           "name": "Listen for Xdebug",
           "type": "php",
           "request": "launch",
           "port": 9000,
           "log": true,
           "pathMappings": {
               "/var/www/sites/prod/docroot":"${workspaceRoot}",
           },
           "hostname": "0.0.0.0" //add this if xdebug.remote_host = host.docker.internal
       }
   ]
}

Debuggin xdebug setup:

  • use this on the host to see if vscode xdebug is running on 9000. Run these commands after you have started debug session in VSCode
lsof -PiTCP -sTCP:LISTEN | grep 9000 
  • use this inside php container to check if port 9000 is open
nc -zv host.docker.internal 9000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment