Docker+PHPstorm+xdebug 配置

1,591 阅读1分钟

PHP安装xdebug扩展

我使用的docker环境,dnmp的镜像。安装xdebug的步骤:传送门

配置Xdebug

  • 修改php.ini文件

    zend_extension=xdebug.so
      xdebug.remote_enable=1
      ; xdebug.remote_handler="dbgp"
      ; docker推荐采用如下形式表示和phpstorm所在机器的ip(如果你的phpstorm装在宿主机那就是宿主机的ip)
      xdebug.remote_host=host.docker.internal
      xdebug.remote_port=9003
      xdebug.remote_log=/var/log/php/xdebug.log
      xdebug.idekey=PHPSTORM
      xdebug.mode = debug
      xdebug.remote_mode="req"
      xdebug.remote_autostart =1
      
      ;启用代码自动跟踪 (可以不添加)
      xdebug.auto_trace = On
    
      ;启用性能检测分析 (可以不添加)
      xdebug.profiler_enable = On
      xdebug.profiler_enable_trigger = On
      xdebug.profiler_output_name = profiler.out.%t.%p
    
  • 查看xdebug是否安装成功 image.png

配置PHPSTORM

  • docker 开启tcp 2375 端口

处于安全原因,Docker Mac 客户端并没有开启 2375 端口的配置,所以我们可以用 socat 来 fork 一个端口出来。

参考这个为什么要开启2375以及怎样开启

怎样开启--也可以只看上面的

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 127.0.0.1:2375:2375 bobrik/socat TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock

调试的时候这个必须是要开启的

image.png

image.png

image.png

  • 创建PHP-CLI解释器 image.png image.png image.png image.png image.png

开始调试

  • 开启调试

image.png

  • 网页上访问, 刷新界面

image.png

其他问题

phpstorm 调试总是断点在index.php的第一行

image.png

参考链接

使用 Docker 在 PHPStorm 中进行 Xdebug

使用phpstorm远程连接docker调试xdebug