Page tree

This page will describe how to configure xdebug for PHPStorm

Configure php environment in docker

  • Add XDEBUG_HOST  and XDEBUG_PORT  to .env file in your docker folder

Where XDEBUG_HOST is your host machine IP address, that is accessible from the PHP container (check ifconfig/ipconfig).

Explanation: PHPStorm should listen when running on that port and ip for debug connections. So you configure here xdebug where to connect to.

If working not at the usual place (offline / Pausa Cafe etc) the here configured hostname / ip address in XDEBUG_HOST might be different. LAN IP vs WLAN IP for example.



  • Add  XDEBUG_HOST  and XDEBUG_PORT  to your docker-compose file

The configured host and port must be reachable from with in the container, see check below.


host-config mixed

Why do you use "172.18.0.1" in your .env file, and not same value as the preset in .yml-file "host.docker.internal".
And which of these values must be changed when working in a different location?
The one in the .env-file I guess. And then? restart the container with "docker composer up -d" ??


  • Host where PHPstorm runs must be reachable by the docker container, to test go into the container and
    1. call t5 service:ping ${XDEBUG_HOST}:${XDEBUG_PORT}
    2. if using a hostname, DNS entries must be returned (in my case my fritz.box returns three entries: a dead one, the LAN interface, the WLAN interface)
    3. For IPV6 see below separate section
    4. The dead IP does not provide the port 9000
    5. On LAN / WLAN interfaces port 9000 is listening and is reachable by PHP

PHP xdebug configuration

This is background knowledge - should all be fine since rolled out with docker container.

In the PHP container xdebug is configured in: /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

By default it is configured the following way:

zend_extension=xdebug
xdebug.mode=debug
xdebug.discover_client_host=1
xdebug.log_level=0
xdebug.idekey=PHPSTORM
xdebug.client_host=${XDEBUG_HOST}
xdebug.client_port=${XDEBUG_PORT}

PHPStorm configuration

Port configuration

Ensure that PHPStorm is listening to the correct port (default is 9003 as mentioned above, in my case in the screenshot I use 9000):

File Mapping

Configure file mapping between your local copy and the files inside the container

Go to PHPStorm settings and type Servers into search input

Create a new configuration that should have the host set to your local translate5 host value (port as well)

Set the root folder of your copy of translate5 on the left (see screenshot) to be mapped to /var/www/translate5  on the right (see screenshot)

Enable debug connections

Ensure that PHPStorm is listening to debug connections, check the status line at the bottom: 


Problems with IPv6

In my case PHPStorm was listening by default on IPv6 interface:

But the docker containers are only talking IPv4. The easiest way was to disable IPv6 in PHPStorm, which I was able to do by adding / editing the file phpstorm64.vmoptions in the root of my home directory and adding there the line:

-Djava.net.preferIPv4Stack=true

How to find the config file:

Check https://www.jetbrains.com/help/phpstorm/tuning-the-ide.html how to find the right config file!

Now netstat looks better:


Browser

Install helper

  • Install XDebug helper extension for your browser

Configure it:

The IDE Key should / must be the same as in the xdebug configuration in php.ini files, so by default PHPSTORM in our docker containers.


Enable debugging 


  - Enjoy (wink)


  • No labels