Mac + Xdebug 3 + Docker Compose + Apache

How do you configure and setup Xdebug 3 in Docker based on php:7.3-apache image?

index.php

<?php
phpinfo(); // I have a breakpoint in this line

Dockerfile

FROM php:7.3-apache
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
COPY index.php /var/www/html/index.php

docker-compose.yml

version: '3.7'
services:
backend:
build: .
image: my-php:latest
ports:
- "4000:80"
environment:
XDEBUG_MODE: debug
XDEBUG_CONFIG: "
client_host=host.docker.internal
start_with_request=yes
"

I run

docker-compose build
docker-compose up

and can access my app on http://localhost:4000/

How do I configure Intellij to stop at the breakpoint in index.php?

---

Intellij Ultimate 2020.3

macOS Catalina 10.15.7

Docker

  • Desktop 2.5.0.1
  • Engine: 19.03.13
  • Compose: 1.27.4
0
7 comments

What configuration phase are you currently on? Do you have a Docker Compose file in your project already?

 

To add the XDebug extension, you may need to add the following part to your Dockerfile:

RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
0

Thanks for sharing your configuration. When it was started as-is, I have noticed the "develop" mode instead of "debug" and "start_with_request" with "default" in the phpinfo() output. Not sure why but only the "client_host" env variable is applied in your scenario.

However, you may just create an "xdebug.ini" file with the following content:

zend_extension=xdebug
xdebug.mode = debug
xdebug.start_with_request=yes

And copy it with the Dockerfile:

COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

Afterwards, just do the build again and it should work like a charm.

0

Vasiliy Yur The output of phpinfo() is misleading. Even though phpinfo still shows mode=develop, Step Debugger is enabled.

I also tried your approach copying xdebug.ini, but Intellij does not stop at the breakpoint in index.php? Did you get it working?

0

Thanks, I saw this SO thread and I think that in this case, it is more about the "start_with_request = default" (and default for "debug" mode is "trigger", not "yes"). At least, in my case, the option is not being applied when passed with XDEBUG_CONFIG and I have "default" in phpinfo() output.

As for the xdebug.ini method, I got it working:

Sorry for the silly question but could you please double-check and confirm if "Start listening for PHP Debug incoming connection" is enabled? 

0

Vasiliy Yur Thanks, it's working. I was just missing

xdebug.client_host=host.docker.internal

in xdebug.ini, since I just copied your code and removed the environment variables from docker-compose.yml.

1

Fantastic, thanks for the update!

0

Please sign in to leave a comment.