[solved] How to setup xdebug and phpstorm
php - Using Xdebug and PhpStorm with Docker container on Windows - Stack Overflow
phpstorm - Xdebug CLI in Docker - Stack Overflow
My xDebug + Docker + PhpStorm config I use from project to project for years
Videos
Thanks to LazyOne's I took another look into the configuration and found out that the Step Debugger is disabled.
I install Xdebug in the following way in my php-fpm Dockerfile:
# Install xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
And this is my original Xdebug configuration:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_log=/var/www/storage/logs/xdebug.log
xdebug.remote_mode = req
I added
xdebug.mode = debug
After rerunning docker-compose up I started receiving a Notice in container logs:
rpg-app | NOTICE: PHP message: Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
I found this thread Xdebug: [Step Debug] Could not connect to debugging client
And added:
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
Getting:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_log=/var/www/storage/logs/xdebug.log
xdebug.remote_mode = req
xdebug.mode = debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
Now everything works! :)
Edit: Following LazyOne's comment I updated to Xdebug v3 configuration settings. The result is:
[xdebug]
xdebug.idekey=PHPSTORM
xdebug.mode = debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9001
xdebug.log=/var/www/storage/logs/xdebug.logs
From the looks of it you have set up everything correctly except perhaps the source path mapping (you find it under servers in PHPStorm). This is often the reason breakpoints are not working. Also try to enable the "Break at first line" option.
Unless you really need a docker compose for shipping I highly recommend using Lando. It always has the correct XDebug config and having real (https) URL's to work with helps a lot.