在Docker中使用PhpStorm和Xdebug调试Symfony2 [英] Debug Symfony2 in Docker with PhpStorm and Xdebug

查看:618
本文介绍了在Docker中使用PhpStorm和Xdebug调试Symfony2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PhpStorm调试Symfony应用程序,方法如下:
https: //gist.github.com/chadrien/c90927ec2d160ffea9c4



我做的完全一样,但效果不佳。

  php-fpm:
build:./php
container_name:php-fpm-symfony
links:
- db
ports:
- 9000:9000
- 8448:8448
- 8000:8000
working_dir:/ var / www / html /
卷:
- ../:/var/www/html
volumes_from:
- data
tty:true
env_file:
- ./docker。 env
环境:
XDEBUG_CONFIG:remote_host = 192.168.0.176

Dockerfile



 #XDEBUG 
RUN yes | pecl安装xdebug \
&&& echozend_extension = $(find / usr / local / lib / php / extensions / -name xdebug.so)> /usr/local/etc/php/conf.d/xdebug.ini \
&&& echoxdebug.remote_enable = on>> /usr/local/etc/php/conf.d/xdebug.ini \
&&& echoxdebug.remote_autostart = off>> /usr/local/etc/php/conf.d/xdebug.ini

当我启动用PhpStorm调试,好像连接正在发生。在我的浏览器中弹出一个新窗口。我的Symfony主页就在这里。
但是它不会在我的断点上停止。而且一步一步的调试不起作用。



我做错了什么?

解决方案

暴露9000与docker-for-mac是错误的 - 你的方向错误。



IDE,PHPstorm,侦听端口9000,这意味着,它在这个9000上打开一个套接字,它不连接到此端口。



另一方面,xdebug连接,附加,通常是localhost的9000端口,如果发现一个监听器,他们会说话。这样,由于9000没有服务,转发端口不仅没有意义,它实际上也伤害了你,因为9000端口将被占用在OSX主机本地主机上,而您的PHPstorm将不再能够听。 / p>

你想做的是


  1. 删除'9000:9000' li>
  2. 使用此配置 https://gist.github.com/EugenMayer/3019516e5a3b3a01b6eac88190327e7c
    a)为您的OSX localhost环回设备创建一个别名
    b)将您的FPM xdebug配置为connect_back到此ip

  3. 现在,非常简单,只是您按此按钮 https://drive.google.com/file/d/0B3SrxyqujSqxeFZoMmdrbDB6SzQ/视图,所以它没有上面的这个红色图标,但它都是绿色的。
    4)现在使用浏览器,像往常一样使用xdebug插件,例如 https ://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc 或Firefox替代品,因为您不希望在xdebug配置中使用autostart,因为我假设

这是它的


  1. 可移植到其他开发者设备由于环回设备别名

  2. ,您不需要配置debug-env,而是使用快速调试,几乎在所有情况下更方便


I'm trying to debug a Symfony app with PhpStorm by following this tutorial: https://gist.github.com/chadrien/c90927ec2d160ffea9c4

I did exactly the same but it does not work well.

php-fpm:
    build: ./php
    container_name: php-fpm-symfony
    links:
        - db
    ports:
        - 9000:9000
        - 8448:8448
        - 8000:8000
    working_dir: /var/www/html/
    volumes:
        - ../:/var/www/html
    volumes_from:
        - data
    tty: true
    env_file:
        - ./docker.env
    environment:
        XDEBUG_CONFIG: remote_host=192.168.0.176

Dockerfile

# XDEBUG
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=off" >> /usr/local/etc/php/conf.d/xdebug.ini

When I'm launching the debug with PhpStorm, it seems like the connection is happening. A new window pop up in my browser. My Symfony homepage is here. But it does not stop on my breakpoint. And the step by step debug does not work.

Did I do something wrong?

解决方案

Exposing 9000 with docker-for-mac is wrong - you got the direction wrong.

The IDE, PHPstorm, listens on the port 9000, this means, it opens a socket on this 9000, it does not connect to this port.

On the other hand, xdebug connects, attaches, to the port 9000 of, usually, localhost - if it finds a listener, they speak. This, since there is no service on 9000, forwarding the port does not only not make sense, it actually harms you even, since port 9000 will be taken on OSX host localhost, and your PHPstorm will no longer be able listen on it.

What you want to do is

  1. Remove '9000:9000'
  2. Use this configuration https://gist.github.com/EugenMayer/3019516e5a3b3a01b6eac88190327e7c to a) create an alias for your OSX localhost loopback device b) configure your FPM xdebug to connect_back to this ip
  3. Now, very simple, just you press on this button https://drive.google.com/file/d/0B3SrxyqujSqxeFZoMmdrbDB6SzQ/view so it does not have this "red icon" above but it is all green. 4) Now using your browser, use an xdebug plugin as usual like https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc or Firefox alternatives, since you do not really want to use "autostart" in the xdebug config, as i suppose

Thats it, it is

  1. portable to other dev devices due to the loopback device alias
  2. you do not need to configure a debug-env, but rather use quick-debug which is, nearly in all cases, more convenient

这篇关于在Docker中使用PhpStorm和Xdebug调试Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆