简体   繁体   English

如何连接 PhpStorm 和 Xdebug

[英]How to connect PhpStorm with Xdebug

I hope somebody here can help me with my issue:我希望这里有人可以帮助我解决我的问题:

I recently gotten into my first PHP project and need to set up debugging.我最近进入了我的第一个 PHP 项目,需要设置调试。 I'm aware many people had the same problem before me but I struggle to find a solution.我知道很多人在我之前遇到过同样的问题,但我很难找到解决方案。

I need to set up PhpStorm with Xdebug and with all settings made its still not working and when I start my debug session i get stuck at this with no further information:我需要使用 Xdebug 设置 PhpStorm 并且所有设置仍然无法正常工作,当我开始调试 session 时,我陷入了困境,没有更多信息:

在此处输入图像描述

This is my project setup:这是我的项目设置:

Docker Webapp with Xdebug: 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp Docker Webapp with Xdebug: 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp

PhpStorm PHP Debug Settings: PhpStorm PHP 调试设置:

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

Xdebug settings from phpinfo() :来自phpinfo()的 Xdebug 设置:

在此处输入图像描述

Listening to debug connections in PhpStorm is on, starting a debug session create a session via GET: https://localhost/?XDEBUG_SESSION_START=16957 but all my breakpoints are ignored. Listening to debug connections in PhpStorm is on, starting a debug session create a session via GET: https://localhost/?XDEBUG_SESSION_START=16957 but all my breakpoints are ignored.

Trying to get more information I ran netstat :为了获得更多信息,我运行了netstat

在此处输入图像描述

Can anyone tell me what I am missing here?谁能告诉我我在这里缺少什么?

Thank you very much in advance!非常感谢您!

  1. Don't use run/debug configurations for web debugging, it's counter-productive.不要对 web 调试使用运行/调试配置,这会适得其反。 You can initiate debugging connections from the browser directly using zero-configuration debugging .您可以使用零配置调试直接从浏览器启动调试连接。
  2. Disable xdebug.remote_connect_back , it brings more harm than profit, especially with Docker.禁用xdebug.remote_connect_back ,弊大于利,尤其是 Docker。
  3. xdebug.remote_host is not supposed to be localhost when you are using Docker, this way, the container is trying to send the debug data to itself instead of the host machine.当您使用 Docker 时, xdebug.remote_host不应该是localhost ,这样,容器会尝试将调试数据发送给自己而不是主机。 It seems that you are using macOS and Docker for Mac, the correct hostname would be host.docker.internal in such a case.您似乎正在使用 macOS 和 Docker for Mac,在这种情况下,正确的主机名将是host.docker.internal
  4. If after you initiate a debugging session from the browser PhpStorm still cannot catch a connection, we'll need to take a look at the Xdebug log as @LazyOne suggested.如果在您从浏览器 PhpStorm 启动调试 session 后仍然无法捕获连接,我们需要按照@LazyOne 的建议查看 Xdebug 日志。

A blog post showing Docker in PhpStorm basics: https://blog.jetbrains.com/phpstorm/2018/08/quickstart-with-docker-in-phpstorm/在 PhpStorm 基础知识中显示 Docker 的博客文章: https://blog.jetbrains.com/phpstorm/2018/08/quickstart-with-docker-in-phpstorm/

i used this setting and it worked:)我使用了这个设置并且它有效:)

xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_host=host.docker.internal
xdebug.remote_enable=1
xdebug.remote_connect_back=0

with launch.json in vscode在 vscode 中使用 launch.json

 "name": "Listen 9000",
 "type": "php",
 "request": "launch",
 "log": true,
 "externalConsole": false,
 "pathMappings": {
        "/var/www/html": "/Users/folder/project/src"
     },
  "port": 9000,

With docker-compose.yml:使用 docker-compose.yml:

在此处输入图像描述

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

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