This is a trashpost mostly used to store all the links I had in my tab. Also, I might need it again or it could help someone. There might me incomplete, missing or conflicting information below so take this with a grain of salt.
Dockerfile
Whatever you Dockerfile
contents are, add these somewhere sensible,
before EXPOSE
or COPY
usually:
RUN apk add --no-cache $PHPIZE_DEPS linux-headers && \
pecl install xdebug && docker-php-ext-enable xdebug
docker-compose.yml
Base for the docker-compose.yml
is below. Note the .ini
files in
volumes:
version: "3.9"
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: php-fpm-81
container_name: my-app
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
error_reporting.ini
The contents of the error_reporting.ini
are simple, and in fact could be
omitted, but we wanna debug:
error_reporting=E_ALL
xdebug.ini
The contents of docker-php-ext-xdebug.ini
are the most important:
zend_extension=xdebug
[xdebug]
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.discover_client_host=true
xdebug.idekey=VSCODE
xdebug.mode=develop,debug
xdebug.start_with_request=yes
launch.json
Even though I use neovim
everything, for debugging I did not have time to
setup it yet. Using off-the-shelf vscode for an occasional debug is
currently enough:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/": "${workspaceFolder}"
}
}
]
}
Should be enough for debugging via docker-compose
and vscode. Enjoy!
Links
- https://code.visualstudio.com/api/extension-guides/debugger-extension
- https://dev.to/jackmiras/xdebug-in-vscode-with-docker-379l
- https://dev.to/oranges13/phpstorm-xdebug-alpine-on-docker-13ff
- https://matthewsetter.com/setup-step-debugging-php-xdebug3-docker/
- https://php.tutorials24x7.com/blog/how-to-debug-php-using-xdebug-visual-studio-code-and-docker-on-ubuntu
- https://stackoverflow.com/questions/46825502/how-do-i-install-xdebug-on-dockers-official-php-fpm-alpine-image
- https://torbjornzetterlund.com/xdebug-a-php-docker-container-in-vs-code/#gsc.tab=0
- https://www.appsloveworld.com/docker/100/163/how-to-add-xdebug-to-php8-1-fpm-alpine-docker-container