How to run or debug php on Visual Studio Code (VSCode)
There is now a handy guide for configuring PHP debugging in Visual Studio Code at http://blogs.msdn.com/b/nicktrog/archive/2016/02/11/configuring-visual-studio-code-for-php-development.aspx
From the link, the steps are:
- Download and install Visual Studio Code
- Configure PHP linting in user settings
- Download and install the PHP Debug extension from the Visual Studio Marketplace
- Configure the PHP Debug extension for XDebug
Note there are specific details in the linked article, including the PHP values for your VS Code user config, and so on.
Debugging PHP with VSCode using the vscode-php-debug extension
VSCode can now support debugging PHP projects through the marketplace extension vscode-php-debug.
This extension uses XDebug in the background, and allows you to use breakpoints, watches, stack traces and the like:
Installation is straightforward from within VSCode: Summon the command line with F1 and then type ext install php-debug
There is a much easier way to run PHP, no configuration needed:
- Install the Code Runner Extension
- Open the PHP code file in Text Editor
- use shortcut
Ctrl+Alt+N
- or press
F1
and then select/typeRun Code
, - or right click the Text Editor and then click
Run Code
in editor context menu - or click
Run Code
button in editor title menu - or click
Run Code
button in context menu of file explorer
- use shortcut
Besides, you could select part of the PHP code and run the code snippet. Very convenient!
As far as I read about it today, you can't debug anything else than node.js, JavaScript and TypeScript at the moment, but they said they want to add new languages which you can debug. The editor is still in development. Nevertheless, I don't think there will be a php debugger in the future since php is serverside, so you can't debug it on your client alone.
If you want to debug php, I can recommend xDebug.
Updated:
Now, it is possible to debug with VS code. You need to install XDebug and php-debug extension for VScode.