Sep 23, 2024
0
Level 8
Does anyone know how to make XDebug (v3) work with VSCode and Laravel in a Docker/Podman container?
Hi I am trying to make XDebug work with Laravel on VSCode. XDebug works for me on local development, but when I try to make it work on a Docker (or Podman) container, it will not work. Connection is succesful, but it won't stop on break points.
It might have something to do with pathMappings in the launch.json file but I'm not sure what to write there that will match 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
This is how I run the container:
docker run -d -p 8000:8000 -p 9003:9003 xdebug
What can I do to fix that if the XDebug logs show that everything is OK?
Thanks
Please or to participate in this conversation.