Debug PHP with VSCode and Docker
Managed to solve my issue with the following settings:
launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"externalConsole": false,
"pathMappings": {
"/srv/app/cms": "${workspaceRoot}/cms",
},
"ignore": [
"**/vendor/**/*.php"
]
},
]
}
xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.idekey=VSCODE
xdebug.remote_autostart=1
xdebug.remote_log=/usr/local/etc/php/xdebug.log
Since xdebug version 3 there are breaking changes in config names.
My current working dockerfile:
RUN apt-get update; \
apt-get -y --no-install-recommends install \
php7.4-dev \
php-pear \
libcurl3-openssl-dev \
libmcrypt-dev \
libxml2-dev \
libpng-dev \
; \
pecl install xdebug; \
{ \
echo "[xdebug]"; \
echo "zend_extension=$(find /usr/lib/php/ -name xdebug.so)"; \
echo "xdebug.mode=debug"; \
echo "xdebug.start_with_request=yes"; \
echo "xdebug.client_host=host.docker.internal"; \
echo "xdebug.client_port=9001"; \
} >> /etc/php/7.4/mods-available/xdebug.ini; \
phpenmod -v 7.4 xdebug; \
VSC debug config:
"configurations": [
{
"name": "XDebug (Docker)",
"type": "php",
"request": "launch",
"port": 9001,
"pathMappings": {
"/var/www/app": "${workspaceRoot}",
}
}
]
More info: https://xdebug.org/docs/upgrade_guide