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
Please sign in to leave a comment.
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:
Vasiliy Yur I've updated my post.
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:
And copy it with the Dockerfile:
Afterwards, just do the build again and it should work like a charm.
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?
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?
Vasiliy Yur Thanks, it's working. I was just missing
in xdebug.ini, since I just copied your code and removed the environment variables from docker-compose.yml.
Fantastic, thanks for the update!