I am unable to get the VSCode debugger to work with PHP running in a podman container. I was able to set this up using Docker by following these steps…
- Create php.dockerfile (Dockerfile)
- Create php.ini
- Add VSCode debugging launch configuration to VSCode settings.json
- Create container in Docker
- Start container
- Open workspace folder of the PHP script in VSCode
- Add breakpoints in the PHP script in VSCode
- Start Debugger in VSCode
- Run PHP script in docker container which will trigger the debugger in VSCode
I believe it is due to some networking setup with Podman which requires additional configuring for the debugger attach itself to the PHP script in the Podman container.
Any help will be most appreciated.
Dockerfile php.dockerfile
FROM docker.io/php:cli
# Install xdebug for nicer error messages
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
php.ini
[PHP]
; xdebug settings for debugging
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=xdebug://gateway
VSCode debugger launch config…
"launch": {
"configurations": [
{
"name": "PHP (Container): Terminal",
"type": "php",
"request": "launch",
"pathMappings": {
"/usr/src/app/": "${workspaceFolder}"
}
}
]
},
Terminal commands to set this all up and run the script
$ docker image build -t my-php-image -f php.dockerfile .
$ docker container create --name my-container -v ./app/:/usr/src/app/ -v .:/usr/local/etc/php/ -w /usr/src/app/ -it my-php-image
$ docker container start my-container
$ docker container exec -it my-container php -d xdebug.start_with_request=yes test.php
You must log in or # to comment.