Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appkr/08b27aa2f98b6b107cf71d04572233d8 to your computer and use it in GitHub Desktop.
Save appkr/08b27aa2f98b6b107cf71d04572233d8 to your computer and use it in GitHub Desktop.
How to use Xdebug Debugger for a PHP project running on a docker

1 Set Xdebug in docker

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.

2 Set IDE

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

3 Set Cookie

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;

4 Make a Breakpoint & Send a Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment