When I use Xdebug with VSCode (and the PHP Debug extension) locally on my Windows host, it works fine.
But when I try to use Xdebug on a docker/podman container, it doesn’t work – it won’t stop on breakpoints, even though the connection is succesful.
This is my Dockerfile
:
# Use official PHP image with FPM and CLI
FROM php:8.2-fpm
# Install system dependencies and PHP extensions for Laravel
RUN apt-get update && apt-get install -y
git
unzip
libpq-dev
libonig-dev
libxml2-dev
libzip-dev
&& docker-php-ext-install pdo pdo_mysql pdo_pgsql zip mbstring xml
# Install Xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
# Configure Xdebug
RUN echo "zend_extension=xdebug.so" >> /usr/local/etc/php/php.ini
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/php.ini
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/php.ini
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/php.ini
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/php.ini
&& echo "xdebug.remote_port=9003" >> /usr/local/etc/php/php.ini
&& echo "xdebug.log=/tmp/xdebug.log" >> /usr/local/etc/php/php.ini
&& echo "xdebug.idekey=VSCODE" >> /usr/local/etc/php/php.ini
# Install Composer globally
COPY --from=composer:2.4 /usr/bin/composer /usr/bin/composer
# Set the working directory to /var/www
WORKDIR /var/www
# Copy the Laravel project to the container
COPY . .
# Install Laravel dependencies
RUN composer install --no-interaction --prefer-dist --optimize-autoloader
# Set permissions for storage and cache
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache
# Expose port 8000 for Laravel's Artisan serve
EXPOSE 8000
# Start the Laravel development server
CMD php artisan serve --host=0.0.0.0 --port=8000
And this is how I build and run the container:
podman build . -t=xdebug
podman run -d -p 8000:8000 -p 9003:9003 xdebug
The output of xdebug_info()
shows that the connection is successful and no errors.
I read somewhere that it might have to do with pathMappings
: https://github.com/xdebug/vscode-php-debug/issues/653#issuecomment-919385770
Though I tried a few options and it still didn’t work (Maybe the issue is related to pathMappings
, but couldn’t make it work still. What should my values be in this case? It’s a Laravel project if that matters)