简体   繁体   English

如何在WSL上使用Xdebug + PhpStorm调试Symfony 4?

[英]How to debug Symfony 4 with Xdebug + PhpStorm on WSL?

I have a PHP7.1 + nginx setup on Windows Linux Subsystem (WSL). 我在Windows Linux子系统(WSL)上安装了PHP7.1 + nginx。
I'm mentioning WSL, so that in PhpStorm Xdebug is configured as a remote debugger, which connects via port 9000. Still WSL and PhpStorm using the same physical files. 我提到WSL,所以在PhpStorm Xdebug中配置为远程调试器,它通过端口9000连接。仍然使用相同的物理文件WSL和PhpStorm。

For Symfony 4 project I'm using it's built in web-server: bin/console server:run 对于Symfony 4项目,我使用它内置的web-server: bin/console server:run

I've managed to set up PhpStorm to accept Xdebug connections. 我设法建立PhpStorm以接受Xdebug连接。 When the connection is established it asks or file mappings. 建立连接后,它会询问或提交映射。 I would expect index.php to be asked for, but the file mapping requested is: vendor/symfony/web-server-bundle/Resources/router.php . 我希望得到index.php ,但请求的文件映射是: vendor/symfony/web-server-bundle/Resources/router.php

As said in the docs inside this file - this file implements rewrite rules for PHP built-in web server. 正如在该文件中的文档中所述 - 该文件实现了PHP内置Web服务器的重写规则。 Okay. 好的。

If I accept the mapping to this file - debugging starts at router.php goes a few lines further and than nothing else happens. 如果我接受映射到这个文件 - 调试从router.php开始进一步,而不是没有其他事情发生。 It doesn't jump to my public/index.php or doesn't stop on any breakpoint. 它不会跳转到我的public/index.php或者不会在任何断点上停止。

The question is - how to configure Symfony 4 debugging with Xdebug? 问题是 - 如何使用Xdebug配置Symfony 4调试? Maybe it is something wrong with mappings or what? 也许是映射还是什么问题?

Through https://www.jetbrains.com/help/phpstorm/override-server-path-mappings-dialog.html , you should extend your file mappings. 通过https://www.jetbrains.com/help/phpstorm/override-server-path-mappings-dialog.html ,您应该扩展文件映射。 Probably, router.php was used as it was the first entry point to be found - but through this first file, you can see the file structure that WSL uses. 可能使用router.php ,因为它是第一个可以找到的入口点 - 但是通过第一个文件,您可以看到WSL使用的文件结构。

So: opening the mapping dialog should give you router.php somewhere down the structure with a mapped path which is also somewhere in a deeper directory. 所以:打开映射对话框应该给你router.php在结构的某个地方有一个映射路径,它也位于更深的目录中。 If you add a mapping for your root folder with the same mapping than the one used for router.php , removing vendor/symfony/web-server-bundle/Resources/router.php , you should be done 如果为根文件夹添加映射的映射与用于router.php映射相同,删除vendor/symfony/web-server-bundle/Resources/router.php ,则应该完成

I experienced a very similar issue, where it seems that after the initial break (First line of script), xdebug cannot continue walking through code. 我经历了一个非常类似的问题,似乎在初始中断(第一行脚本)之后,xdebug无法继续遍历代码。

PhpStorm 2017.3, Mojave 10.14, Symfony 4.2, Xdebug 2.7.1 PhpStorm 2017.3,Mojave 10.14,Symfony 4.2,Xdebug 2.7.1

Try upgrading PhpStorm to 2018.3 - it was the difference for me. 尝试将PhpStorm升级到2018.3 - 这对我来说是不同的。

You have to reinstall ssh on WSL first: 您必须首先在WSL上重新安装ssh:

sudo apt remove openssh-server
sudo apt install openssh-server

Edit /etc/ssh/sshd_config , change PasswordAuthentication to yes and add your login user to the bottom of the file: AllowUsers yourusername 编辑/ etc / ssh / sshd_config ,将PasswordAuthentication更改为yes并将您的登录用户添加到文件的底部: AllowUsers yourusername

Save your changes and restart ssh: 保存更改并重新启动ssh:

sudo service ssh --full-restart

More info here: https://www.illuminiastudios.com/dev-diaries/ssh-on-windows-subsystem-for-linux/ 更多信息: https//www.illuminiastudios.com/dev-diaries/ssh-on-windows-subsystem-for-linux/

At the end set remote debugging config in PhpStorm: http://blog.spameri.cz/2017/04/20/phpstorm-wsl-php.html 最后在PhpStorm中设置远程调试配置: http//blog.spameri.cz/2017/04/20/phpstorm-wsl-php.html

Remember to set proper directory mapping. 请记住设置正确的目录映射。 For PhpStorm your files are in C:/ProjectsDir/MyProject, but for xdebug it's /mnt/c/ProjectsDir/MyProject 对于PhpStorm,您的文件位于C:/ ProjectsDir / MyProject,但对于xdebug,它是/ mnt / c / ProjectsDir / MyProject

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

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