4

Can't debug the web app with the following configuration:

Dockerfile:

FROM php:7-fpm

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_host=site.dev" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_log=/var/www/site/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini

WORKDIR /var/www/site

nginx server (site.conf):

server {
    server_name site.dev www.site.dev;
    root /var/www/site/src/UI/Web/Silex/Public;
    ...
}

docker-compose.yml:

version: '2'
services:
    php:
        container_name: acme_php
        build: etc/docker/development/php
        volumes:
            - ./:/var/www/site
    nginx:
        container_name: acme_nginx
        build: etc/docker/development/nginx
        ports:
            - "80:80"
        volumes:
            - ./:/var/www/site
            - ./etc/docker/development/nginx/site.conf:/etc/nginx/conf.d/site.conf
        links:
            - php

Running the server:

docker-compose up -d --build

Server:

enter image description here

Debug:

enter image description here

Run/Debug configurations:

enter image description here

Pressing bug button opens chrome but doesn't stop in the breakpoint:

enter image description here

Running phpinfo() looks like (xdebug area):

enter image description here

xdebug.log:

I: Connecting to configured address/port: site.dev:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/site/src/UI/Web/Silex/Public/index.php" language="PHP" xdebug:language_version="7.1.5" protocol_version="1.0" appid="6" idekey="18032"><engine version="2.5.4"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///var/www/site/src/UI/Web/Silex/Public/index.php" lineno="5"></xdebug:message></response>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

Why it is not stopping in the breakpoint? :(

jj-aa
  • 1,019
  • 5
  • 19
  • 39
  • 1
    1) Collect xdebug log to see what is happening (where it tries to connect .. if at all) 2) Try specifying IP address of client computer (where IDE runs) manually (in case if it cannot detect correct one) 3) try with `xdebug_break();` in your code 4) Maybe it does not see your "debug this" marker (cookie/query param)? Try with `xdebug.remote_autostart = 1` 5) Firewall? Ensure that IDE can receive incoming requests on xdebug port (it's xdebug that connects to IDE and not other way around) – LazyOne May 17 '17 at 18:56
  • BTW -- "PHP | Servers" -- "Host" field should not contain any `http://` stuff -- just a domain name. ALSO -- you should close other debug tabs -- maybe it's debugging one of them already..? – LazyOne May 17 '17 at 18:59
  • 1) Dont know where xdebug log file is 2) Where I should specify this IP 3) Don't see any output doing this 4) done 5) I can listen PHP Debug connections. Host field fixed "site.dev" now. Same, doesn't stop in the breakpoint – jj-aa May 17 '17 at 19:17
  • 1) https://xdebug.org/docs/all_settings#remote_log 2) https://xdebug.org/docs/all_settings#remote_host 3) https://xdebug.org/docs/all_functions – LazyOne May 17 '17 at 19:51
  • got the following log: I: Checking remote connect back address. I: Checking header 'HTTP_X_FORWARDED_FOR'. I: Checking header 'REMOTE_ADDR'. I: Remote address found, connecting to 172.20.0.1:9000. W: Creating socket for '172.20.0.1:9000', poll success, but error: Operation now in progress (29). E: Could not connect to client. :-( – jj-aa May 17 '17 at 20:03
  • 1
    No concrete idea. Could be firewall. Could be wrong IP (unlikely, but double check). Try different port (e.g. 9001 in both xdebug and PhpStorm settings). BTW -- on Mac IDE is unable to recognize who listens on xdebug port (cannot tell if it's busy already). You may check output of `sudo lsof -nP -iTCP -sTCP:LISTEN` to see who listens on xdebug port – LazyOne May 17 '17 at 20:37
  • Running the command I've got: phpstorm 2272 jordi 103u IPv4 0xa14927c7fd6fb343 0t0 TCP *:9000 (LISTEN) – jj-aa May 17 '17 at 21:34
  • Updated question with xdebug.log after changes in Dockerfile – jj-aa May 17 '17 at 21:49
  • Why have you changed `remote_host` to `site.dev`? What IP it points to? I guess -- it points to Docker container. So far (the latest xdebug log) it looks like now you are connecting to PHP-FPM that also runs on TCP 9000 but inside Docker -- xdebug connects to some service that does not understand the protocol. The best I can suggest right now -- delete that "PHP | Servers" entry that you have made in PhpStorm and let it create it itself (it will help you to do that once it will receive incoming xdebug connection) -- see what will be created (maybe you have filled some fields wrong). – LazyOne May 17 '17 at 21:59
  • site.dev points to 127.0.0.1 in my hosts file. "PHP | Servers" entry updated (also updated the question). Same logs and same "Waiting for connection with ide key N" in Debugger tab on PHPStorm – jj-aa May 17 '17 at 22:13
  • *"site.dev points to 127.0.0.1 in my hosts file"* Still -- where it points to inside the Docker? Better use IPs in such places. *" "PHP | Servers" entry updated"* Is that created by IDE (was there a popup asking for mapping etc?) Since it's a remote debug (code is run inside Docker container) it should have asked about mapping... Right now I'm out of other meaningful suggestions (your original setup was quite OK at first glance). If I could see it live (interact myself) then I may spot some nuances/wrong stuff ... but right now I may only suggest to try the old magic -- "restart computer"... – LazyOne May 17 '17 at 22:31
  • I know -- using Docker containers means no SSH ... but if you can temporarily install SSH into such container .. try connecting with telnet from there to your PhpStorm (on xdebug port of course) and to see if you can connect that way. *"Operation now in progress (29). E: Could not connect to client."* When you had this error I thought that you just need to verify IP:port and firewall and it would work (as long as PhpStorm is the one that listens on xdebug ports). I still think it needs to be looked in that direction... as so far xdebug connection does not reach to PhpStorm for some reason. – LazyOne May 17 '17 at 22:37

2 Answers2

2

Changes to make it work:

Dockerfile:

FROM php:7-fpm

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/xdebug.ini \

WORKDIR /var/www/site

docker-compose.yml:

version: '2'
services:
    php:
        container_name: acme_php
        build: etc/docker/development/php
        volumes:
            - ./:/var/www/site
        links:
            - db
        environment:
          XDEBUG_CONFIG: "remote_host=192.168.1.99"
          PHP_IDE_CONFIG: "serverName=site.dev"
    nginx:
        container_name: acme_nginx
        build: etc/docker/development/nginx
        ports:
            - "80:80"
        volumes:
            - ./:/var/www/site
            - ./etc/docker/development/nginx/site.conf:/etc/nginx/conf.d/site.conf
        links:
            - php

/etc/hosts (host machine):

127.0.0.1 site.dev

Thanks for all the help in your comments @LazyOne

jj-aa
  • 1,019
  • 5
  • 19
  • 39
  • 1
    So .. in the end it basically was the wrong IP address of the computer where IDE is running (`xdebug.remote_host` .. which you set now a bit differently)... OK. Good to know. – LazyOne May 18 '17 at 08:07
0

I had the same problem , my config:

  • Ubuntu 19.10
  • Visual Code
  • Docker version 19.03.5 docker-compose
  • docker-compose version 1.25.0

add this Dockerfile: :

echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini &&

Info:

Xdebug for remote server not connecting

maccevedor
  • 155
  • 2
  • 5