简体   繁体   中英

Docker toolbox Xdebug not working with PhpStorm

I tried all the tutorials I found on the internet and still can't use a simple break point in PhpStorm using docker toolbox...

I currently have this inside my Dockerfile :

# Install xdebug
RUN pecl install xdebug; \
    docker-php-ext-enable xdebug; \
    echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "xdebug.remote_host=192.168.99.100" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "xdebug.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;

Xdebug gets installed and configured correctly ( php -i output):

xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => 192.168.99.100 => 192.168.99.100
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9001 => 9001
xdebug.remote_timeout => 200 => 200
xdebug.idekey => PHPSTORM => PHPSTORM

In my PhpStorm configuration I have the following:

Proxy:

DBGp 代理

Debug调试

PHP interpreter PHP 解释器

Debug config调试配置

Server configuration服务器配置

The blurred items are Username and project name .

I have 2 folders in a project, one called docker and holds all the docker files and one site , that holds all the site files.

The configuration for my docker-compose is the following:

version: '3'

services:
  application:
    image: project_image:latest
    environment:
      - C_UID=${C_UID:-1000}
      - C_GID=${G_UID:-1000}
      - DEVELOPMENT=${DEVELOPMENT:-1}
      - ~/.ssh:/var/www/.ssh
      - ~/.composer:/var/www/.composer
    env_file:
      - .env
    volumes:
      - ${APPLICATION:-../site}:/phpapp
    ports:
      - 9001:9001

  nginx:
    image: dockerwest/nginx-laravel:${NGINXVERSION:-stable}
    environment:
      - VIRTUAL_HOST=${BASEHOST:-project_name.docker},${EXTRAHOSTS}
    volumes:
      - ${APPLICATION:-../site}:/phpapp
    links:
      - application
    ports:
      - 80:80

Anyone a clue on what I'm doing wrong here?

When I try to de telnet 192.168.99.100 9001 , the connection can't be made, port 9000 , neither, but port 80 gives me a good response.

Anyone who has an idea what's going on here?

Xdebug needs to open a connection to PhpStorm. You don't need the ports exposed in Docker, or do anything with the Xdebug proxy. The telnet needs to be done from within your docker container to PhpStorm. The IP address in xdebug.remote_host , needs to be the IP address of your IDE, and not the IP address of your docker container (where HTTP/Apache listens on port 80).

3 conditions must be fulfilled for xdebug to work remotely with VirtualBox, I had it especially in connection with Docker inside virtualbox.

1) remote_connect_back=1 or the exact ip address of your host machine (which can differ often) must be listed in the remote_host config field (, sometimes both at the same time don't work together, especially in the case of a docker being separately from a virtualbox = at windows hyper-v directly)

2) no other application like eg. a web-project can be exposed at the port 9000, that must be reserved for the php editor, or a different port must be reserved by the editor/listened at (or for the php web project), and addressed/transmitted to from the php, it is a project-based configuration

3) it's similar to the second point, VirtualBox must have no port forwarding to that port, as it would effectively occupy it but it must be reserved for the php editor, not for virtualbox port forwarding. Not virtualbox has to listen at that port to be forwarded to some internal app, but the outer php-editor has to listen for it=that port

It is also worth emphasizing that is it either xdebug.remote_host OR xdebug.remote_autostart. This is mentioned both in the docs and the previous comment .

In other words - If you are having the feeling that your remote_host setting is being ignored, check if remote_autostart is not accidentally turned on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM