apt install php7.4-debug
nano etc/php/7.4/apache2/php.ini
[Xdebug]
xdebug.mode = debug
xdebug.client_host = host.docker.internal
xdebug.client_port = 29003 ; default is 9003 but I had a conflict with that port
xdebug.start_with_request = yes
zend_extension=xdebug.so
xdebug.mode=debug
/etc/init.d/apache2 restart
Alternatively, you could add this to near the end of your Dockerfile:
# Install Xdebug
RUN PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;") && \
apt-get install -y "php${PHP_VERSION}-xdebug"
# Append Xdebug settings to php.ini
RUN PHP_INI_DIR=$(php -i | grep php.ini$ | rev | cut -d ' ' -f 1 | rev) && \
{ \
echo '[Xdebug]'; \
echo 'xdebug.mode = debug'; \
echo 'xdebug.client_host = host.docker.internal'; \
echo 'xdebug.client_port = 29003'; \
echo 'xdebug.start_with_request = yes'; \
echo 'zend_extension=xdebug.so'; \
} >> "$PHP_INI_DIR"
# Restart Apache to apply changes
RUN /etc/init.d/apache2 restart
Add to your docker-compose.yml
services:
php:
ports:
- 29003:29003
In VSCode: .vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 29003,
"pathMappings": {
// you'll figure out the mappings when it first doesn't work
// could be something like
// "/var/www/html": "${workspaceRoot}/src"
}
}
]
}