php - 使用 Visual Studio Code 配置调试 PHP 的问题

标签 php visual-studio-code wamp xdebug

我正在尝试按照本教程在 VS Code 上配置 XDebug:

https://blogs.msdn.microsoft.com/nicktrog/2016/02/11/configuring-visual-studio-code-for-php-development/

但在这一点上:

enter image description here

vs 代码不显示 PHP 选项。

我尝试重新安装 VS Code 和 XDebug。 我试图重新安装 php 服务器并更改 de PHP 服务器,但没有任何效果。

我创建了其他教程,但向我展示了同样的问题:当我点击齿轮时,只显示没有 php 选项的 launch.json

enter image description here

最佳答案

对于我自己来说,齿轮图标也没有任何作用,所以为了生成所需的 PHP 配置,我切换了下拉菜单并单击了添加配置,它在 launch.json< 中设置了两个 PHP 配置:

{
    "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
}

正如 PHP 调试 扩展文档所确认的那样,这两个配置都是通过单击齿轮图标生成的配置(如果它有效的话):

监听 XDebug

Listen for XDebug This setting will simply start listening on the specified port (by default 9000) for XDebug. If you configured XDebug like recommended above, everytime you make a request with a browser to your webserver or launch a CLI script XDebug will connect and you can stop on breakpoints, exceptions etc.

启动当前打开的脚本

Launch currently open script This setting is an example of CLI debugging. It will launch the currently opened script as a CLI, show all stdout/stderr output in the debug console and end the debug session once the script exits.

其次,确保您已按照说明正确设置了 PHP 调试 扩展:

This extension is a debug adapter between VS Code and XDebug by Derick Rethan. XDebug is a PHP extension (a .so file on Linux and a .dll on Windows) that needs to be installed on your server.

Install XDebug I highly recommend you make a simple test.php file, put a phpinfo(); statement in there, then copy the output and paste it into the XDebug installation wizard. It will analyze it and give you tailored installation instructions for your environment. In short:

On Windows: Download the appropiate precompiled DLL for your PHP version, architecture (64/32 Bit), thread safety (TS/NTS) and Visual Studio compiler version and place it in your PHP extension folder. On Linux: Either download the source code as a tarball or clone it with git, then compile it. Configure PHP to use XDebug by adding zend_extension=path/to/xdebug to your php.ini. The path of your php.ini is shown in your phpinfo() output under "Loaded Configuration File".

Enable remote debugging in your php.ini:

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

There are other ways to tell XDebug to connect to a remote debugger than remote_autostart, like cookies, query parameters or browser extensions. I recommend remote_autostart because it "just works". There are also a variety of other options, like the port (by default 9000), please see the XDebug documentation on remote debugging for more information.

If you are doing web development, don't forget to restart your webserver to reload the settings.

Verify your installation by checking your phpinfo() output for an XDebug section.

关于php - 使用 Visual Studio Code 配置调试 PHP 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55398821/

相关文章:

php - 整个组高级自定义字段的输出字段

php html渲染忽略样式

PHP Post 变量有重复的、已修改的数据

wordpress - 我可以在 Microsoft Azure(Bizspark 帐户)上安装 WAMP 吗?

php - Woocommerce 结帐页面中的承运商自定义字段验证

visual-studio-code - 寻找用于 i18n 资源包编辑的 visual studio 代码扩展

visual-studio-code - Visual Studio Code files.autoSave onFocusChange 不起作用

visual-studio-code - 从资源管理器重命名时更改(或添加)VS Code 中的背景颜色

php - 我的 WAMP 网页使用哪个 PHP Ini 文件?

python - MySQL - 无法定义外键