5

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 Answer 1

8

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.

The two necessary settings in php.ini are:

Sign up to request clarification or add additional context in comments.

9 Comments

@felixfbecker Is there a way to launch the browser when starting the debug? Obviously with the Web server already running?
@Sergio Not yet, feel free to do a PR
@felixfbecker Could you explain all those steps... Presently, I am able to debug but no browser get opened when I do Launch currently open script or I am able to open the site in IIS Express when I do IIS Express : Restart Web Site but my breakpoint does not get hit. And if I try to do both, either it does not works (waiting forever) or it shows an error message like the port already used. In the past, I have used Visual Studio» and also Web Matrix and it was 100 time easier to set up and require only minimal understanding.
When I do Listen for XDebug nothing happen. I have no idea why! If I type localhost:9000 in a browser, nothing happen. If I start the browser using the command palette, then the page display without stopping on breakpoints.
@Phil1970 did you follow the instructions in the readme/on xdebug.org to setup XDebug? Verified it's enabled in phpinfo()? Checked logs?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.