Skip to content

Instantly share code, notes, and snippets.

@lelinhtinh
Last active July 12, 2024 10:09
Show Gist options
  • Save lelinhtinh/968d64ddbdc59ad6ff28636d3ab3cd72 to your computer and use it in GitHub Desktop.
Save lelinhtinh/968d64ddbdc59ad6ff28636d3ab3cd72 to your computer and use it in GitHub Desktop.
Docker - VSCode - XDebug - PHP 7.4
services:
app:
volumes:
- .docker/xdebug.ini:/usr/local/etc/php/conf.d/99-xdebug.ini
extra_hosts:
- 'host.internal.docker:host-gateway'
FROM 7.4-fpm-alpine
RUN apk add php7-pecl-xdebug
RUN cp /usr/lib/php7/modules/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug on Docker",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html/": "${workspaceFolder}"
}
}
]
}
zend_extension=xdebug
[XDebug]
xdebug.client_host=host.internal.docker
xdebug.client_port=9000
xdebug.mode=debug,develop
xdebug.idekey=vsc
xdebug.start_with_request=yes

In VSCode:

  • Install extension: xdebug.php-debug
  • Goto settings, update PHP › Debug: Ide Key: "php.debug.ideKey": "vsc"

If host.internal.docker not working, change xdebug.client_host by your IP address:

  • macOS: ipconfig getifaddr en0
  • Windows with WSL: grep nameserver /etc/resolv.conf | cut -d ' ' -f2
  • Linux (Debian based distros): hostname -I | cut -d ' ' -f1

Use XDebug Wizard to get exact installation instructions, then update copy location in Dockerfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment