Dec 15, 2025 10:53 PM

Setting up Xdebug with PHPStorm and Docker

Here's a straight-to-the-meat tutorial on how to use XDebug with PHPStorm when your code lives in a Docker container. This is for Xdebug version 3.

Configure XDebug in your PHP container

You docker container running PHP (phpfpm most likely) must be configured to use Docker.
To do so, makes sure that PHP loads the XDebug config file. E.g. for a Debian container and php-fpm 8.0, you must have the file /etc/php/8.0/fpm/conf.d/20-xdebug.ini. In this file, put the following config:

zend_extension=xdebug.so  
  
xdebug.mode=debug   
# default for linux, for mac use "host.docker.internal"  
xdebug.client_host=172.17.0.1  
xdebug.client_port=9003
# Uncomment the line below to have XDebug trigger systematically (on each request or CLI script)
# xdebug.start_with_request=yes

Explanation of the parameters:

Then there's the xdebug.start_with_request. If you specify it to yes, then XDebug will alwyas trigger PHPStorm, whether you launched a web request or a PHP script. If you use this parameter, you'll have to enable the Run > Start listening for PHP debug connections in PHPStorm, but you won't be able to use a specific Debug configuration, which I don't really like.

Configure PHPStorm

Next, head into PHPStorm preferences, and go to PHP > Servers. Create a server and configure it like this:

The last step of configuration is under Run > Edit configuration.
Create a PHP remote debug configuration:

CleanShot 2022-10-06 at 15.08.09@2x.png
Click OK to save the settings.

Triggering a debug session

Now the configuration is done, all you have to do to start debuggin is to first add a breakpoint in your code. Next, you have several options (all explained on Xdebug official documentation):


Reference

XDebug - Step debugging
PHPStorm - Configure XDebug