8

My problem is that xdebug doesn't work when I start listening port. I think PhpStorm can't link with xdebug. I just get debugger panel variables are not available. It's looks like xdebug have not correct settings.

Software and versions used:

Ubuntu 16.04 LTS
Docker v 17.06
docker-compose 1.15

So I was trying many times setup xdebug + Docker + PhpStorm but cannot do it. I've read many tutorials but nothing haven't helped me.

My docker-compose.yml looks like this:

version: '3'
services:
    web:
        image: nginx:latest
        ports:
            - "80:80"
        restart: on-failure
        volumes:
            - "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
            - "./etc/ssl:/etc/ssl"
            - "./project:/var/www/html/project"
        depends_on:
            - php
            - db

    php:
        image: nanoninja/php-fpm
        restart: on-failure
        volumes:
            - "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
            - "./project:/var/www/html/project"
    db:
        image: mysql
        container_name: ${MYSQL_HOST}
        restart: on-failure
        env_file:
            - ".env"
        environment:
            - MYSQL_DATABASE=${MYSQL_DATABASE}
            - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
            - MYSQL_USER=${MYSQL_USER}
            - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION
        ports:
            - "8988:3306"
        volumes:
            - "./data/db/mysql:/var/lib/mysql"

My xdebug.ini is:

xdebug.default_enable=0
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=0
xdebug.idekey="PHPSTORM"
xdebug.profiler_enable=0
xdebug.remote_host=localhost

PhpStorm settings:

enter image description here

enter image description here

enter image description here

enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Rider_BY
  • 1,129
  • 1
  • 13
  • 31
  • How about you describe what your problem is first – Hatted Rooster Sep 17 '17 at 10:29
  • See if this helps http://tarunlalwani.com/post/debugging-php-xdebug-docker/ – Tarun Lalwani Sep 17 '17 at 11:05
  • 1) Collect xdebug logs for such unsuccessful debug session and share it -- https://xdebug.org/docs/all_settings#remote_log 2) Why `xdebug.remote_host=localhost` if you are running it in Docker? It must be an IP of the computer where PhpStorm is running. – LazyOne Sep 17 '17 at 12:44

2 Answers2

11

Docker on Linux allows Xdebug to automatically connect back to the host system so you can just set xdebug.remote_connect_back=1 and leave out the xdebug.remote_host in your xdebug.ini.

Paweł Napierała
  • 1,631
  • 10
  • 15
10

I found out solution how to run xdebug.

1) First of we need create a new static route that will based on your network device. For create new static route: run in terminal ifconfig

and found out the exists network device. In my situation name of device will be as

wlp4s0

enter image description here

2) Go ahead. Let's begin create the static route. In terminal run command like this:

> sudo ip addr add 10.254.254.254/24 brd + dev wlp4s0 label wlp4s0:1

3) Now if you run again ifconfig you'll see new static route: enter image description here

4) Update

xdebug.ini

file add:

xdebug.remote_host=10.254.254.254

5) Update docker.compose.yml file: in php section add:

environment:
    PHP_IDE_CONFIG: "serverName=project-docker"
    PHP_XDEBUG_ENABLED: 1
    XDEBUG_CONFIG: remote_host=10.254.254.254

6) The last thing is update phpstorm settings.

Server settings: phpstorm settings Remote debug config: phpstorm settings 7) And profit xdebug is working: xdebug is working

Rider_BY
  • 1,129
  • 1
  • 13
  • 31
  • 2
    Do you **actually** have DBGp Proxy installed and running? It's a separate thing that you need to install and configure separately. If you don't (which is used very rarely .. and simply not required for a local single dev work) -- then please remove that part to avoid confusion/misleading other users with similar issues. – LazyOne Sep 17 '17 at 14:32
  • Yes. You were right. DBGP Proxy I haven't installed proxy. – Rider_BY Sep 17 '17 at 14:37