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

保罗

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

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

但在这一点上:

在此处输入图片说明

vs代码未显示PHP选项。

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

我创建了其他教程,但向我展示了相同的问题:单击齿轮时,仅显示不带php选项的launch.json

在此处输入图片说明

脚本47

For myself, the gear icon did nothing too, so to generate the required PHP configuration I toggled the drop down and clicked Add Configuration and it setup two PHP configurations in launch.json:

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

Both of those two configuration are the sames ones that would've been generated by clicking the gear icon (had it worked) as is confirmed by the PHP Debug extension documentation:

Listen for 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

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.

Secondly, ensure that you have setup the PHP Debug extension correctly as per the instructions:

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

除了remote_autostart之外,还有其他告诉XDebug连接到远程调试器的方法,例如cookie,查询参数或浏览器扩展。我建议使用remote_autostart,因为它“可以正常工作”。还有许多其他选项,例如端口(默认为9000),请参阅远程调试的XDebug文档以获取更多信息。

如果您正在进行Web开发,请不要忘记重新启动Web服务器以重新加载设置。

通过检查phpinfo()输出的XDebug部分来验证安装。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章