Home > front end >  Use Xdebug with dockerized PHP project
Use Xdebug with dockerized PHP project

Time:10-19

Recently I've started to work on a new project that is dockerized and has Xdebug module. Also I've checked in container itself and 9000 port is listening and has Xdebug module version 2.9.8

I don't have any PHP or anything installed on my Ubuntu (host system).

In my PhpStorm I set my PHP interpreter manually:

enter image description here

Also set DBGp proxy like

enter image description here

Also created a server:

enter image description here

This is my etc/hosts: and I call API in Postman with the following address: api.vendet.local/api/v1/test

UPDATED path mapping: enter image description here

Still not break in any point. What is the problem and how can I do that?

CodePudding user response:

Be aware that as long as you are not using network_mode: "host" for the php container localhost / 127.0.0.1 for Xdebug running within the container is not the same as localhost on your Ubuntu host!

To be able to connect to Xdebug from PHPStorm you need to ensure the following:

  • the debugger is listening on an IP reachable from the host: listening on 127.0.0.1 it would only be accessible from within the container itself. Connecting to 127.0.0.1:9000 on the host will be forwarded to the container, but to the virtual network interface of the container and not to the loopback device. To simply listen on all devices within the container specify 0.0.0.0 as address
  • path mappings are enabled - since (most probably) the paths of the PHP files within the container are not identical with the paths to the same files on the host.

CodePudding user response:

I've checked in container itself and 9000 port is listening

It is IDE that should be listening on port 9000, not the container.
#1: you don't need to use DBGp proxy.
#2: at PHP | Servers you have to enable "Use path mappings".

If I were you, I would delete all the configuration you made in PhpStorm (#1 & #2) and would start from the scratch.
First: make sure to configure XDebug properly in a container, see Configure Xdebug running in a Docker container. Pay attention to the value of xdebug.client_host described in the article.
Then: just run a simple Zero-configuration debugging

  • Related