DEV Community

Xdebug in PhpStorm with Docker

Jack Miras on December 17, 2021

In my last post, I talked about how to configure Xdebug in VSCode with Docker. Now, I would like to share how we can build upon our previous Docker...
Collapse
 
nuryagdym profile image
nuryagdym

Thanks for article!
I want to add some notes.

  1. I set my host address like this "xdebug.client_host=host.docker.internal" in xdebug.ini
  2. xdebug.mode=develop,coverage,debug,profile in this config "profile" mode made debugging extremely slow.
  3. For debugging CLI commands, I additionally set this environment variables in PHP container env:
    1. PHP_IDE_CONFIG="serverName=Docker-laravel_scaffold".
    2. XDEBUG_TRIGGER=docker - the same value you set in xdebug.ini for xdebug.trigger_value
Collapse
 
jackmiras profile image
Jack Miras • Edited

@nuryagdym how are you doing?

Thanks for adding the notes, I really appreciate it!

I just would like to leave it an observation about setting xdebug.client_host=host.docker.internal... Last time I've checked this didn't work for all OS (Linux, Mac, and Windows) while setting the IP works for the three of them.

For anyone else reading this comment, if your OS works by setting the client host this way, I recommend that you do it because it will save you from having to update your IP address from time to time.

Also, could you to share what have you done about the xdebug.mode=profile? Have you removed it to avoid slowness? I'm asking because other people reading the article and comments may run in the same problem.

Once again, thanks for adding the notes.

Collapse
 
nuryagdym profile image
nuryagdym

I am good thank, hope you are well also :).
xdebug.client_host=host.docker.internal does work on my Mac.

I removed profile mode from xdebug.mode. I had a heavy CLI command which runs hours, and profile mode was creating cacheGrind log files which become huge (millions of rows).

Collapse
 
jonpontet profile image
JP

Yes! Thank you!
I couldn't get Xdebug 3 working with Docker + WordPress on Mac. It was adding the PHP Remote Debug configuration and using xdebug.idekey that made the difference.

Collapse
 
andythedandy profile image
Andy Eberle-Bannert

Thanks!

"Notice that the Port matches the port from our previsouly built docker-compose.yml" <- Which docker-compose.yml?

Is there something like

ports:
  - 8000:9003
Enter fullscreen mode Exit fullscreen mode

in there?

Collapse
 
jackmiras profile image
Jack Miras

Hello @andythedandy, how are you doing?

Thanks for quoting this part of the post, it was, in fact, missing external links pointing to the other two posts that serve as base to this one.

Talking about the PHP > Servers configuration, we are pointing to port 8000 because we are connecting to the service in our docker-compose stack that has PHP ready to go.

As you will notice, this service which is called app gets built based on a Dockerfile, also explained in a previous post.

Both the post where I share how do I usually build my Dockerfile and docker-compose.yaml are now linked in the same session that initially got you confused.

In case you've notice anything else in this post or if you have other questions, feel free to reach me out.

Collapse
 
mydls_1 profile image
Илья

DC
services:
nginx:
container_name: nginx
build:
context: ./_docker/nginx
dockerfile: Dockerfile
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
networks:
- internal
php:
container_name: php-fpm
build:
context: ./_docker/php-fpm
dockerfile: Dockerfile
volumes:
- ./src:/var/www/html
- ./_docker/php-fpm/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
tty: true
networks:
- internal
networks:
internal:
driver: bridge

Image description

The problem is that I need to reload the page in the browser every time, otherwise it does not show the debug point.

Collapse
 
lebru profile image
le-bru

Hi,
thanks for that tutorial. Sort of got it to run.

However, the moment I tell PHP Storm to listen for debugging connections, any request to my application would run into a timeout.
Only if I tell PHPStorm to listen for debugging connections, the request will be processed, and also only by clicking on "Resume Program" in the Debug window.

Is that intended behavior or is there something wrong with my setup?

My understanding so far was, that program execution should only be interrupted if there are breakpoints set.

Collapse
 
jackmiras profile image
Jack Miras • Edited

Hello @lebru,

I didn't experience this issue, but In case you didn't resolve this issue yet, please mail me at jackmiras@gmail.com with more details and prints and/or videos about the problem… I'll reproduce it as soon as I can.

Collapse
 
josemiguelq profile image
Jose Miguel

A definitive tutorial and explanation

Collapse
 
tieutantan profile image
Tran Ngoc Tan

thank you, I need your guide