How do I configure xDebug in PHPStorm in using Docker containers?

Hi all,

Been getting to grips with Dockerizing my new Laravel app using this Laracast series - - I've set things up exactly as per this and all works great!

I would now like to install xDebug in order to debug using my IDE which is PHPStorm and I'm not really sure what I need to do. There seem to be a plethora of different options in PHPStorm for setting up debugger options, PHP interpreters, servers, configuration options - I don't really know where to start!

Just as a starting point, I HAVE managed to install xDebug with this in my php.dockerfile:

FROM php:8-fpm-alpine
RUN adduser -g ${PHPGROUP} -s /bin/sh -D ${PHPUSER}
RUN sed -i "s/user = www-data/user = ${PHPUSER}/g" /usr/local/etc/php-fpm.d/www.conf
RUN sed -i "s/group = www-data/group = ${PHPGROUP}/g" /usr/local/etc/php-fpm.d/www.conf
RUN mkdir -p /var/www/html/public
RUN docker-php-ext-install pdo pdo_mysql
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]

 And my PHPinfo() shows that xDebug3 is installed and running - so that's a start - I just don't know what to do next!

I have also SSH'd into my PHP container and confirmed that `host.docker.internal` is working.

Any help here would be great!

Thank you

1 comment

Hi there,

Check these articles. One of them may be what you are after.

Bonus :) ("In this video I teach myself how to run PHP's built-in web server to run a (very simple) Laravel application inside a Docker container, and then configure Xdebug and PhpStorm to do step debugging." Derick Rethans, Xdebug author)


Please sign in to leave a comment.