0

I'm sorry in advance, I did my research and I noticed the same question multiple times on this page, I've been trying to figure it out by myself but I can't quite comprehend how to get this working with my specific configuration

This is a project from work which has this Dockerfile:

FROM php:7.3-apache
RUN apt-get update && apt-get install -y acl unzip \
    && rm -r /var/lib/apt/lists/*

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
RUN install-php-extensions gd intl pdo_mysql soap xdebug zip

RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_port=10000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_host=172.17.0.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

WORKDIR /var/www/app

COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer

COPY docker/000-default.conf /etc/apache2/sites-enabled/000-default.conf
COPY docker/app.conf /etc/apache2/conf-enabled/z-app.conf
COPY docker/app.ini $PHP_INI_DIR/conf.d/app.ini

RUN ln -s $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
RUN a2enmod rewrite

It's supposed to already have Xdebug working, no?

I installed the php debug extension on VSCode and this is my launch.json config:

{
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 10000,
            "pathMappings": {
                "/var/www/app": "${workspaceFolder}"
            },
}

I start the debugging session but the project doesn't stop on breakpoints, so I'm just lost

I hope you guys can help me out, thanks!

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Gabriel
  • 149
  • 3
  • 8
  • 1) Execute some PHP script with `phpinfo();` in it to see if Xdebug is enabled and configured. 2) `echo "xdebug.remote_host=172.17.0.1"` This IP might be different every time you build your docker image... https://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container 3) IF all is good -- enable and collect Xdebug log -- it will show where it tries to connect and what the response is. Maybe it's your firewall (if everything is good from Xdebug side) – LazyOne Nov 23 '20 at 17:52
  • @LazyOne I'm guessing these commands should be ran from inside the docker container? – Gabriel Nov 23 '20 at 18:22
  • Which commands exactly? For #1 -- the same way you are trying to debug -- it's just to check that all is good. For #2 you could use `host.docker.internal` instead of an IP (but right now it only works on Mac & Windows; on Linux you need to detect the IP dynamically when making/starting your docker image). For #3 -- Xdebug log is set via the same php.ini. Just make sure it will be saved somewhere that will be accessing from outside (so you can read the log). P.S. And just in case: it's Xdebug that connects to IDE/editor .. so this will be a connection from inside the Dockerto your host OS. – LazyOne Nov 23 '20 at 18:40
  • @LazyOne hmm, so here's my confusion, this php.ini has to be the one used on the docker container, right? How could I make it write to somewhere I can read while the container runs? – Gabriel Nov 23 '20 at 18:47
  • @LazyOne Also, do I need to set the Xdebug ip to be the same as the docker container ip? – Gabriel Nov 23 '20 at 18:51
  • 1) Yes, php.ini is used inside the container. 2) It's for Xdebug log (`xdebug.remote_log`) -- it needs to point into some file that you can read from outside (e.g. persistent volume or whatnot). It could be internal cache folder as well ... you just need to read the log content from it 3) The IP should be the host OS IP as seen from inside the container (as Xdebug will be establishing the connection from inside the container back to your host OS). https://learnxdebug.com/ – LazyOne Nov 23 '20 at 19:30

0 Answers0