DEV Community

Discussion on: Using Xdebug with Docker

Collapse
 
dvdvdmt profile image
Dmitriy Davydov • Edited

I've used this xdebug.ini placed in /usr/local/etc/php/conf.d/

[Xdebug]
xdebug.remote_enable = true
xdebug.remote_port = 9000
xdebug.remote_host = host.docker.internal

Where host.docker.internal is the proper way to access your host ip address in a containerized app in Docker Desktop clients.

NOTE: Set your debug port in WebStorm to 9000 (Languages & Frameworks > PHP > Debug).

Also you need to add the next line to your Dockerfile or set environment field in docker-compose.yml

ENV PHP_IDE_CONFIG="serverName=<server-name-in-PhpStorm-servers>"

After that you need to press "Start listen on PHP debug connections" (phone icon), set a breakpoint and start a debug session (bug icon). To trigger the debug session you access your API endpoint via GET, POST, with query param ?XDEBUG_SESSION_START=PHPSTORM or cookie set to XDEBUG_SESSION = PHPSTORM. To set this cookie easily you can use Xdebug Helper extension or a similar one.