doumin1897
2016-04-17 17:03 阅读 1.1k
已采纳

如何使用VS Code启动和调试php?

I'm new to VS Code and the php world. My experience is more with heavyweight IDE such as Visual Studio. However, I have a need to setup a php environment on my dev machine and am having some trouble getting it to work properly.

My environment is a Win 10 dev machine. I am using VS Code and php ver 5.5. I have properly installed the xdebug extension and verified it is properly installed. I have also installed the php-debug extension in VS Code.

The challenge I'm having and have been unable to find any useful information through google is launching the php website from within VS Code and then being able to debug it.

A few things I have tried, but haven't worked.

  1. I installed the iis-express extension to VS Code which allows for running any folder through iis express. https://marketplace.visualstudio.com/items?itemName=warren-buckley.iis-express This works, but the website doesn't display properly. IIS returns an error message saying the site is not properly configured. It's apparently missing a mapping or something along those lines.

  2. I followed this blog. http://blog.denouter.net/2015/05/run-php-from-visual-studio-code.html and am able to run the website using the built in php web server.

  3. Installed webmatrix and let the windows platform installer correctly install and wire up iis express to work with php. The same folder works fine when running from webmatrix.

  4. Installed the php-debug extension to VS Code. https://github.com/felixfbecker/vscode-php-debug

Here is what I think I'm missing. I believe I need to launch the website from within VS Code for the debugging to work. I can't figure out how to "launch" the php website from within VS Code. The php-debug extension from VS Code only supports launch. It doesn't support "attach" mode. I suspect this is why when I run the website outside VS Code, the debugger doesn't work. Let me be clear, the debugger is working when I hit F5, it just doesn't ever stop on any breakpoints.

To summarize: How can I launch and debug my php website from within VS Code? I'm looking for a detailed step by step guide.

Thank you

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongshi6528 dongshi6528 2016-06-22 11:35

    I am the author of vscode-php-debug. You do not need to "launch the website" from inside VS Code. When you start the "Listen for XDebug" configuration from the debug section, VS Code (or rather, my debug adapter) will listen on port 9000 for XDebug. You need to run a web server like Apache, IIS or nginx locally on your PC and configure it to serve PHP files - this has nothing to do with VS Code. Then simply open a web browser and navigate to localhost and XDebug will connect to the debugger, stopping on breakpoints.

    点赞 9 评论 复制链接分享

相关推荐