php with xdebug: Unable to debug console PHP in Visual Studio Code when using podman (Works in Docker)
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
I fiddle around with podman some more and found that changing these two things will make debugging work with podman. However this will force the container to use the host network and therefore the container will not get its own network space.
Not sure if this is a good way to go about it for a PHP development environment or if there is a better way to achieve this. The problem with docker setup in the original post compared to podman is when using those steps for podman, the debugger cannot connect to the IDE (VSCode) since the podman container network is isolated as its own network.
If anyone else knows of a better way to go about this, please do share