xdebug 3ep Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port) code example

Example: xdebug: [step debug] could not connect to debugging client. tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

PHP 7.4
Docker
PHPStorm 2020.1
Xdebug 3.1.0

Install Xdebug in your docker container using Dockerfile

RUN pecl install xdebug-3.0.1 && docker-php-ext-enable xdebug
Configure php.ini with following:

[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = 1
Go to PHPStorm - Settings - PHP - Debug - Xdebug and set the port to 9003 (by default)

PHPStorm

That's it (:

If you want to enable/disable debugger only when you need it: just install a browser extension called "Xdebug helper", select "Debug" and remove "xdebug.start_with_request = yes" from php.ini

[xdebug]
xdebug.mode = debug
xdebug.discover_client_host = 1

Tags:

Misc Example