I'm configuring Xdebug in VS Code and it doesn't work when I use the start_with_request=trigger setting.
If I set the config value to yes it works.
I think VS Code is not sending the env variables from the launch.json file.
My Xdebug ini file:
zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = trigger
My launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"env": {
"XDEBUG_TRIGGER": "true"
}
}
]
}
I use VSCode with Microsoft Remote-SSH extension on a Ubuntu VM and Windows 10.
My Xdebug extension is the XDebug official extension.
Log from Xdebug:
[2393] Log opened at 2022-03-29 13:54:04.173262
[2393] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[2393] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[2393] [Config] INFO: Trigger value for 'XDEBUG_SESSION' not found, so not activating
[2393] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[2393] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[2393] [Config] INFO: Trigger value for 'XDEBUG_SESSION' not found, so not activating
[2393] Log closed at 2022-03-29 13:54:04.360936
vscode-php-debug dev here.
This is a common misunderstanding. The provided launch.json only listens for Xdebug/DBGp connections - as the default name implies. If there was also a program setting in there, VS Code would also start a (php) process. And only in that case could VS Code contribute to the environment of that newly started process.
So, assuming you are running a web server, you can only change Xdebug settings by modifying the php.ini or somehow change the process environment of that web server process...
You can also check out other launch.json snippers by typing php at the end of the current snippet. Maybe some of them could be useful.
Perhaps I should add a warning if somebody sets env without setting program...
I'm trying to set a breakpoint in PHP code using XDebug with Visual Studio Code, which is all installed on an Ubuntu Hyper-V virtual machine. I'm on PHP 7.2.
Whenever I set a breakpoint in my PHP code and refresh a page which should hit the breakpoint, I get the errors "command is not available" and "no such breakpoint" shown in popups in Visual Studio Code. I also get the following error in the Debug Console.
XDebugError: command is not available
at new Response (/home/ben/.vscode/extensions/felixfbecker.php-debug-
1.13.0/out/xdebugConnection.js:56:19)
at new BreakpointSetResponse (/home/ben/.vscode/extensions/felixfbecker.php-debug-
1.13.0/out/xdebugConnection.js:207:9)
at Connection.<anonymous> (/home/ben/.vscode/extensions/felixfbecker.php-debug
1.13.0/out/xdebugConnection.js:599:20)
at Generator.next (<anonymous>)
at fulfilled (/home/ben/.vscode/extensions/felixfbecker.php-debug-1.13.0/out/xdebugConnection.js:4:58) {
code: 5,
name: 'XDebugError'
}
Based on my research, I think the problem is because XDebug doesn't work with IPv6, but the debugger is listening on v6. If I do netstat -an | grep 9000, I get
tcp6 0 0 :::9000 :::* LISTEN
Here are the contents of /etc/php/7.2/fpm/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.var_display_max_depth=-1
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
How do I fix this problem and get my breakpoint to work?
I debug using these extensions:
PHP Debug (by Robert Lu)
PHP Intelephense (by Ben Mewburn)
Please check the XDebug configuration for your project. It is a launch.json in a .vscode folder in you projec root directoryt. If it is missing, then you must created in the Debug settings of Visual Studio Code (The gear wheel button).
It should look like this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}"
}
]
}
This was fixed a while back in PHP Debug extension. Here is an issue that talks about it and a linked pull request.
Due to the "synchronous" nature of Xdebug/DBGp and the "asynchronous" one of VS Code it happened a lot that when multiple PHP processes connected to PHP Debug an overlapping of "add add", "remove remove", "add add" process of adding and removing of breakpoints would happen.
Due to this conflict the extension ended up trying to remove a breakpoint that was already removed, and such - not very helpful - exception was presented.
I'm continuing development of PHP Debug so if you have problems or bugs file them there please.
I have a problem to update dependencies in my project. Issue:
Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info
In some cases It's only because of poor or interrupted internet connections
One solution might be changing your internet form Wi-Fi to Ethernet.
If you are using ESET antivirus, go in "Advanced Settings" and disable "HTTP-scanner" under "web access protection"
If you're using Virtualbox, Then you might need to downgrade to resolve the issue
If you are using IPv6, try disabling it.
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
If you are using ESET antivirus, go in "Advanced Settings" and disable "HTTP-scanner" under "web access protection"
If you are using IPv6, try disabling it. If that solves your issues, get in touch with your ISP or server host, the problem is not at the Packagist level but in the routing rules between you and Packagist (i.e. the internet at large). The best way to get these fixed is raise awareness to the network engineers that have the power to fix it.
To disable IPv6 on Linux, try using this command which appends a rule preferring IPv4 over IPv6 to your config:
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
I had this issue too, it ended up being a Virtualbox issue. I needed to downgrade to version 5.1.6 to resolve it. (I was running 5.1.8)
Also, I read that running 5.0.28 also caused this issue, and downgrading to 5.0.10 resolved it.
Add these lines in composer.json and then run composer update.
"repositories": [
{
"type": "composer",
"url": "https://packagist.org"
},
{ "packagist": false }
]
Happy coding!
I can't find a way to run or debug php on Visual studio code, Does anyone know how?
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
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.
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/type Run 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
Besides, you could select part of the PHP code and run the code snippet. Very convenient!
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.
If you don't want to install xDebug or other extensions and just want to run a PHP file without debugging, you can accomplish this using build tasks.
Using Build Tasks (No extensions required)
First open the command palette (Ctrl+Shift+P in Windows, ⌘+Shift+P in Mac), and select "Tasks:Open User Tasks". Now copy my configuration below into your tasks.json file. This creates user-level tasks which can be used any time and in any workspace.
{
"version": "2.0.0",
"tasks": [
{
"label": "Start Server",
"type": "shell",
"command": "php -S localhost:8080 -t ${fileDirname}",
"isBackground": true,
"group": "build",
"problemMatcher": []
},
{
"label": "Run In Browser",
"type": "shell",
"command": "open http://localhost:8080/${fileBasename}",
"windows": {
"command": "explorer 'http://localhost:8080/${fileBasename}'"
},
"group": "build",
"problemMatcher": []
},
{
"label": "Run In Terminal",
"type": "shell",
"command": "php ${file}",
"group": "none",
"problemMatcher": []
}
]
}
If you want to run your php file in the terminal, open the command palette and select "Tasks: Run Task" followed by "Run In Terminal".
If you want to run your code on a webserver which serves a response to a web browser, open the command palette and select "Tasks: Run Task" followed by "Start Server" to run PHP's built-in server, then "Run In Browser" to run the currently open file from your browser.
Note that if you already have a webserver running, you can remove the Start Server task and update the localhost:8080 part to point to whatever URL you are using.
Using PHP Debug
Note: This section was in my original answer. I originally thought that it works without PHP Debug but it looks like PHP Debug actually exposes the php type in the launch configuration. There is no reason to use it over the build task method described above. I'm keeping it here in case it is useful.
Copy the following configuration into your user settings:
{
"launch": {
"version": "0.2.0",
"configurations": [
{
"type": "php",
"request": "launch",
"name": "Run using PHP executable",
"program": "${file}",
"runtimeExecutable": "/usr/bin/php"
}
]
}
// all your other user settings...
}
This creates a global launch configuration that you can use on any PHP file. Note the runtimeExecutable option. You will need to update this with the path to the PHP executable on your machine. After you copy the configuration above, whenever you have a PHP file open, you can press the F5 key to run the PHP code and have the output displayed in the vscode terminal.
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
source : https://www.youtube.com/watch?v=8MLEB1qx984
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
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.
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.
XDebug changed some configuration settings.
Old settings:
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
New settings:
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9000
So you should paste the latter in php.ini file.
More info: XDebug Changed Configuration Settings
The best solution for me was to add a key binding to run PHP code directly in the terminal
To do so you just need to download terminal-command-keys from VS code extensions marketplace:
Then got to File>Preferences>Keyboard Shortcuts and click on the following icon at the upper right corner:
It will open up the keybindings.json file
Add the following settings
[
{
"key": "ctrl+s",
"command":"terminalCommandKeys.run",
"when": "editorLangId == php",
"args": {
"cmd":"php ${file}",
"newTerminal":true,
"saveAllfiles": true,
"showTerminal": true,
}
}
]
key is the shortcut to run your PHP file (I use ctrl+s) you can change it as you wish
when to run different commands for different file types (I set it for PHP files only) vscode's "when" clauses
See the full settings documentation from here
That's it, I hope it helps.
I'm currently trying to set-up satis to manage our internal packages using composer.
I have created my config.json file
{
"name": "Internal Packages",
"homepage": "http://packages.example.org",
"repositories": [
{ "type": "vcs", "url": "ssh://me#mypackages.com/Test-Component" }
],
"require-all": true
}
When I try and build it
php bin/satis build config.json web/
I get the following error:
[ErrorException]
rmdir(/home/lee.stone/.composer/cache): Directory not empty
Warning: You have xdebug.scream enabled, the warning above may be
a legitimately suppressed error that you were not supposed to see.
I have deleted that cache folder and tried to build again, but get the same error. Nothing has been created in my web directory either.
Any ideas on how to solve this problem so it will build succesfully?
Disable the xdebug.scream option of your command line PHP version.
Explanation of that option:
xdebug.scream
Type: boolean, Default value: 0, Introduced in Xdebug >= 2.1
If this setting is 1, then Xdebug will disable the # (shut-up) operator so that notices, warnings and errors are no longer hidden.
If the usage of # does not suppress the expected error when removing that directory in your installation, and that error triggers an exception that shouldn't exist in the first place.