简体   繁体   English

在PhpStorm中使用xdebug通过Docker容器

[英]Using xdebug through Docker container in PhpStorm

I've read some posts about this but none helped in my case or simply overlooked the missing piece. 我已经阅读了一些关于此的帖子,但在我的案例中没有任何帮助,或者只是忽略了丢失的部分。

I cannot get xdebug to work on PhpStorm using a Docker container. 我无法使用Docker容器让xdebug在PhpStorm上工作。

Docker-compose.yml 泊坞窗,compose.yml

version: '2'

services:
  web:
    image: nginx:latest
    volumes:
    - .:/usr/share/nginx/html
    - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    - ./nginx/logs:/var/logs/nginx
    - ./nginx/site-enabled/default.conf:/etc/nginx/sites-enabled/default.conf
    ports:
    - "80:80"
    depends_on:
    - php

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: 1234
      MYSQL_DATABASE: local_db
      MYSQL_USER: root
      MYSQL_PASSWORD: 1234
    ports:
    - "3306:3306"

  php:
    build: images/php
    volumes:
    - .:/usr/share/nginx/html
    - ./config/docker/php/php.ini:/usr/local/etc/php/php.ini
    - ./config/docker/php/ext-xdebug.ini:/usr/local/etc/php/conf.d/ext-xdebug.ini
    - ./config/docker/php/php-fpm.conf:/usr/local/etc/php-fpm.conf
    user: www-data
    depends_on:
    - db

config/docker/php/ext-xdebug.ini 配置/搬运工/ PHP / EXT-xdebug.ini

zend_extension="/usr/lib/php7/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.overload_var_dump=1
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
xdebug.remote_host=172.20.0.1 # ip of host inside docker container
xdebug.remote_log=/usr/share/nginx/html/xdebug.log

error from xdebug.log 来自xdebug.log的错误

Log opened at 2017-05-31 11:01:14
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. :-(
Log closed at 2017-05-31 11:01:14

In PhpStorm I'm using remote debugger with following settings: 在PhpStorm我正在使用具有以下设置的远程调试器:

server 服务器

Host - 127.0.0.1  
Port - 80 

Absolute path on server 服务器上的绝对路径

/usr/share/nginx/html

IDE session key IDE会话密钥

PHPSTORM

Ok I got the solution in here 好的,我在这里得到了解决方案

https://forums.docker.com/t/ip-address-for-xdebug/10460/9 https://forums.docker.com/t/ip-address-for-xdebug/10460/9

I had to set my internal ip to xdebug.remote_host and disable xdebug.remote_connect_back=0 我必须将我的内部ip设置为xdebug.remote_host并禁用xdebug.remote_connect_back=0

Seems this is a osx thing. 似乎这是一个osx的事情。 Hope this helps someone here 希望这能帮到这里的人

I've found that the following config on ext-xdebug.ini works for Docker for Mac 我发现ext-xdebug.ini上的以下配置适用于Docker for Mac

xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal

Docker automatically defines host.docker.internal within containers. Docker自动在容器中定义host.docker.internal So we simply point xdebug to think host.docker.internal is the IP of host machine (which obviously is). 所以我们简单地指出xdebug认为host.docker.internal是主机的IP(显然是)。 This way, we don't have to rely on ever changing internal IP between docker container and host. 这样,我们就不必依赖于在docker容器和主机之间不断更改内部IP。

More information can be found here https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds 更多信息可以在这里找到https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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