Open a shell in the docker. Note that we use php and xdebug in the docker, not in the host machine.
$ docker exec -it 6b04d4c03211 bash
Set the xdebug like the following. xdebug.remote_host=host.docker.internal
is IMPORTANT.
root@6b04d4c03211:/var/www/html# php --ini | grep xdebug
# /etc/php/7.0/cli/conf.d/20-xdebug.ini,
root@6b04d4c03211:/var/www/html# cat /etc/php/7.0/cli/conf.d/20-xdebug.ini
# zend_extension=xdebug.so
# xdebug.idekey=IDEA
# xdebug.remote_enable=1
# xdebug.remote_host=host.docker.internal
# xdebug.remote_port=10001
FYI, in case the OS in Docker is the Ubuntu sudo apt install php-xdebug
do the installation.
Set xdebug in the IDE. The value of the Debug port must be the one set in xdebug.remort_port
of section 1. Here the 10001 port is mapped to 10001 of the host(docker run ... -p 10001:10001
).
Open a project to debug, and set a Server like the following. Note the underlined path mapping.
Start listening for PHP Debug Connections
The cookie key of request must be the one set in xdebug.idekey
of section 1.
XDEBUG_SESSION=IDEA; path=/; domain=localhost; Expires=Tue, 19 Jan 2038 03:14:07 GMT;