I can't find a way to run or debug php on Visual studio code, Does anyone know how?
问题:
回答1:
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.
回答2:
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
回答3:
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.
回答4:
It's worth noting that you must open project folder in Visual Studio Code for the debugger to work. I lost few hours to make it work while having only individual file opened in the editor.
Issue explained here
回答5:
If you are using Ubuntu 16.04 and php7 you can install xdebug with below command:
sudo apt-get install php-xdebug
You can find the full configuration process here.
If you are using windows, you can download xdebug from xdebug.org.
And start debugging in VS-code with php-debug extension.
回答6:
To debug php with vscode,you need these things:
- vscode with php debuge plugin(XDebug) installed;
- php with XDebug.so/XDebug.dll downloaded and configured;
- a web server,such as apache/nginx or just nothing(use the php built-in server)
you can gently walk through step 1 and 2,by following the vscode official guide.It is fully recommended to use XDebug installation wizard to verify your XDebug configuration.
If you want to debug without a standalone web server,the php built-in maybe a choice.Start the built-in server by php -S localhost:port -t path/to/your/project
command,setting your project dir as document root.You can refer to this post for more details.
回答7:
already their is enough help full answers but if you want to see the process then
[ click here ]
Steps in Short
- download php debug plugin [ https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug ]
- download xDebug.dll [ https://xdebug.org/wizard.php ]
- move xdebug file to [ ?? / php / ext / here ]
update php.ini file with following lines :
[XDebug] xdebug.remote_enable = 1 xdebug.remote_autostart = 1 zend_extension=path/to/xdebug
[ good to go ]
- make sure that you have restarted your local server
回答8:
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!