在VSCode上调试Laravel应用程序 [英] Debugging Laravel application on VSCode

查看:1109
本文介绍了在VSCode上调试Laravel应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人成功配置VSCode来调试基于Laravel的网站吗?在阅读了许多文章和教程之后,我已经达到可以让VSCode收听XDEBUG"的地步,但是我无法在 normal 风格的VS调试中进行操作.可以按F5键在我最喜欢的浏览器中启动当前网站,当它达到断点时,它会闯入VSCode,就像我们在完整的Visual Studio或Eclipse中一样.

Has anyone successfully configured VSCode to debug Laravel-based website? After having followed numerous articles and tutorials, I have made it to the point where I can ask VSCode to "Listen to XDEBUG", but I haven't been able to do normal VS-style debugging where I could just hit F5 to launch current the website in my favorite browser and it would break into VSCode when it hit a breakpoint, just like we do in full Visual Studio or Eclipse.

我在机器上正确设置了以下内容:

I have following things correctly setup on my machine:

  • VSCode 1.25.1
  • XAMPP 1.8
  • XDEBUG(已配置且正在运行)
  • VSCode的PHP调试扩展

我不确定在launch.json中需要使用哪种启动配置. PHP Debug扩展附带的两个配置如下所示:

I'm not sure what launch configuration do I need to use in my launch.json. The two configurations that come with PHP Debug extension look like this:

{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9000
},
{
    "name": "Launch currently open script",
    "type": "php",
    "request": "launch",
    "program": "${file}",
    "cwd": "${fileDirname}",
    "port": 9000
}           

虽然第一种配置可以正常工作(我可以在VSCode中以该模式启动调试,然后在浏览器中单独启动我的网站,但遇到断点),但是第二种配置失败.它告诉我无法找到Controller类(这是Laravel框架类).用名称空间来限定类名也没有用.

While the first configuration works correctly (I can start debugging in that mode in VSCode, then launch my website separately in the browser and it hits the breakpoints), the second configuration fails. It tells me that it cannot locate Controller class (which is a Laravel framework class). Qualifying class name with namespace doesn't do any good either.

我的猜测是,这与启动配置的设置有关.它尝试将活动脚本作为一个独立的单元启动,因此无法找到位于不同文件中的框架类的定义.我们必须以某种方式将网站作为单个应用程序提供.

My guess is that this has got something to with how the launch configuration is setup. It tries to launch the active script as an independent unit and thus fails to locate the definition of framework classes located in different files. We have to somehow provide launch the website as a single application.

有人成功做到了,告诉我我在这里想念什么吗?

Has anyone done that successfully and tell me what I'm missing here?

推荐答案

最后使它正常工作.这是其他人需要的东西.

Finally got it working. Here are the things if anyone else needs it.

  1. 确保已在Apache服务器上设置并运行XDEBUG.
  2. 为您喜欢的浏览器安装调试器扩展.扩展程序适用于Chrome,Edge和FireFox(可以从VSCode中搜索和安装).
  3. 设置launch.json,使其并行启动两个配置.这是通过所谓的化合物配置完成的.这是启动PHP + XDEBUG和EDGE浏览器的矿井:

  1. Make sure you have XDEBUG set up and running on your Apache server.
  2. Install debugger extension for your favorite browser. Extensions are available for Chrome, Edge and FireFox (can be searched and installed from within VSCode).
  3. Set up launch.json so that it launches two configs in parallel. This is done through so-called compound configurations. Here is mine that launches PHP + XDEBUG and EDGE browser:

{
    "version": "0.2.0",
    "compounds": [
        {
            "name": "Launch & Debug",
            "configurations": [ "Launch Program", "Launch localhost" ]
        }
],
"configurations": [
    {
        "type": "php",
        "request": "launch",
        "name": "Launch Program",
        "cwd": "${workspaceRoot}",
        "port": 9000
    },
    {
        "name": "Launch localhost",
            "type": "edge",
            "request": "launch",
            "url": "http://localhost/public",
            "webRoot": "${workspaceRoot}"
        }
    ]
}

  • 根据您的本地设置(例如站点地址,xdebug端口等)更新上述配置.
  • 按F5,您的调试会话将开始.浏览器将自动启动,您将可以达到断点.
  • 这篇关于在VSCode上调试Laravel应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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