Goal
Debug with PHP Debug, Xdebug and VSCodium.
Problem
VSCode doesn't start debugging. When I click Start Debugging the blue line under the debugging control buttons appears and moves for a few seconds and then the control buttons disappear. Same when I press the green "Run" button
Also on the left side, where "variables", "watch" and "stack" are shown nothing appears.
Description
I have no experience with the VSCodium debugging options. I used a couple of tutorials (1, 2, 3, videos and tried certainly the proposal from the VSCode PHP Debug extension site (which I use).
I'm using Codium (VSCode without MS) on a Linux Mint 20 machine. PHP 7.4 and Xdebug are installed via Linux Synaptic Package Manager. Of course the Xdebug helper in Firefox is enabled, breakpoints are set and I tried it in different projects. I tried a few things in the php.ini. That's how it looks at the moment:
[XDebug]
xdebug.remote_enable = 1
; xdebug.remote_autostart = 1
; xdebug.remote_connect_back = 1
Xdebug itself is loaded via the /etc/php/7.4/cli/conf.d/20-xdebug.ini and in PhpStorm it works like expected but not in VSCodium.
That's the standard launch.json, which is saved in the .vscode folder in the project root:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Here is a part of my phpinfo() output:
And the xdebug part:
And here the xdebug log when i try it with VSCodium:
[5625] Log opened at 2020-10-04 10:05:20
[5625] I: Connecting to configured address/port: localhost:9000.
[5625] W: Creating socket for 'localhost:9000', poll success, but error: Operation now in progress (29).
[5625] E: Could not connect to client. :-(
[5625] Log closed at 2020-10-04 10:05:20
My guess is, that there is a basic VSCodium debugging thing, I didn't enabled or so. But I don't know, what it could be.
Maybe somebody has an idea?
Finally found the solution. Its a Codium specific bug. At VSCode it works.
Found the solution here:
https://github.com/VSCodium/vscodium/issues/466
make sure you don't have PHP Debug extension installed;
go to https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug and download vsix file using "Resources" → "Download Extension";
in VSCodium go to "Extensions" sidebar and then click three dots icon near
to "Extensions" title;
choose "Install from VSIX…" and select downloaded file.
#LazyOne thanks for your help again :)
Edit:
If you are updated to Xdebug 3.* you have to modify the xdebug section in the php.ini:
Add this:
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9000
You could drop the last line if you change instead the port to 9003 in your launch.json.
See also this GitHub Issue
Related
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'm having an issue with Visual Studio Code and Xdebug.
My System:
I'm using a Windows 10 system with IIS webserver and PHP version 7.4.
I've downloaded and installed Xdebug with the last version (2.9.0) successfully (see the excerpt from the php.ini below).
Visual Studio Code is configured for using Xdebug (see launch.json file below).
My issue is:
When I set a breakpoint, it stops at this breakpoint. So far so good. But if I press then "Step into" (F11) or "Step over" (F10) buttons, nothing is happening at all. The initial breakpoint is still highlighted - it stays at the breakpoint.
Maybe something is configured wrong, but actually I can't figure out what it is.
See here the configuration files:
php.ini:
[XDEBUG]
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.remote_autostart = 1
xdebug.idekey=VSCODE
xdebug.remote_log ="C:\temp\xdebug.log"
[PHP_XDEBUG-2.9.0-7.4-VC15-NTS]
zend_extension = "C:\Program Files (x86)\PHP\v7.4\ext\php_xdebug-2.9.0-7.4-vc15-nts-x86_64.dll"
launch.json of Visual Studio Code:
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"ignore": [
"**/vendor/**/*.php"
]
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
This turned out to be a bug in Xdebug, which would happen when the following points are all true:
An error handler converted a warning/notice into an Exception
An exception breakpoint was set on this specific Exception, or a wild card exception breakpoint was set
The DBGp eval command, which IDEs often use to implement watches, created a warning or notice, in this case, due to an undefined variable.
The cause was that although the eval command turns of breakpoints with a breakpoints_allowed flag until it has been run, the breakpoint handler for exceptions did not check whether this breakpoints_allowed flag was actually set.
The fix is to check for the breakpoints_allowed flag in the handler for exception breakpoints, and will be part of the upcoming Xdebug 2.9.2 release. If you don't want to wait, download Xdebug from Github and make sure to use the xdebug_2_9 branch (unless you want to go really experimental).
When I start the debugger on VSCode everything seems to be working as the lower bar becomes orange etc... However, when I add a breakpoint the site ignores it and keeps the loading normally. When I go to add a config on launch.json php doesn't appears either. Xdebug doesn't creates the log.
I have double-checked all the paths, downloaded the dll of Xdebug and added the necessary lines on the php.ini, settings.json and launch.json.
php -v gives me the version 7.3.5 and on WAMP it's the same version (verified on desktop and http://localhost/?phpinfo=-1)
settings.json
{
"telemetry.enableTelemetry": false,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"window.zoomLevel": -1,
"C_Cpp.updateChannel": "Insiders",
"arduino.path": "C:\\Program Files (x86)\\Arduino",
"[javascript]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"editor.minimap.enabled": false,
"php.validate.enable": true,
"php.executablePath": "c:/wamp64/bin/php/php7.3.5/php.exe",
"php.validate.executablePath": "c:/wamp64/bin/php/php7.3.5/php.exe",
"php.validate.run": "onSave",
"files.associations": {
"*.inc": "php"
},
"git.autofetch": true,
"git.enableSmartCommit": true
}
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": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
php.ini
[XDebug]
zend_extension="c:/wamp64/bin/php/php7.3.5/ext/php_xdebug-2.8.0beta2-7.3-vc15-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart=on
xdebug.remote_port = 9000
xdebug.remote_log="c:/"
I don't get any error messages either.
I was struggling with this issue for over a year but found the problem in my case.
VSCode python debugger will only recognize either CRLF or LF at the end of lines but not both. The debugger will appear to skip lines (but they are still executed) when there is a mix of the two in the file. This was happening in my case because I was adding lines of code while inside a debugging session and when I saved the file with the debugger session still live the end of line characters were different than the default in the file.
To solve it I simply had to change the line feed setting on right side of the bottom blue bar in VSCode from CRLF to LF back to CRLF and save the file.
For making a log: The webserver is probably not allowed to write to c:/ - you probably want to use c:/temp (or whatever your temporary directory path is).
As for not stopping, it is possible that the paths for your webserver and locally on your hard drive are not the same, and you need to set up a "path mapping": https://github.com/felixfbecker/vscode-php-debug/blob/master/README.md#remote-host-debugging
I am attempting to debug php in Visual Studio Code. This is my first project after installing the PHP Debug extension (and also PHP and XDebug as dependencies). The page renders correctly if I have the PHP executable target the file in command prompt "C:\php>php -S 0.0.0.0:9000 c:\users\landerson\documents\vs_proj\php_example\index.php". However if I begin debugging in Visual Studio with configuration "Listen for XDebug", the page will be stuck loading until I stop the debugging process.
I am following Microsoft's blog entry explaining initial setup: https://blogs.msdn.microsoft.com/nicktrog/2016/02/11/configuring-visual-studio-code-for-php-development/. I suspect not fully understanding the instruction "Make sure to point your webserver root to your project and each time you request a PHP file" may be what is tripping me up. I've tried with and without executing the command prompt entry. That seems to only effect what happens after I stop the debugging process. I've entered my phpinfo() results into https://xdebug.org/wizard.php and followed the instructions. I have neither an index.php nor a php.ini in C:\php and have both in c:\users\landerson\documents\vs_proj\php_example
index.php
<?php
$myvar = "Hello ";
$myvar = $myvar . "PHP World!";
echo $myvar;
?>
Bottom of php.ini
zend_extension = C:\php\ext\php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
C:\Users\landerson\AppData\Roaming\Code\User\settings.json
{
//"http.proxyStrictSSL": false,
"php.validate.enable": true,
"php.validate.executablePath": "C:\\php\\php.exe",
"php.validate.run": "onType"
}
launch.json
{
"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}",
"port": 9000
}
]
}
I would expect that at least without breakpoints the page would load and adding breakpoints would utilize the PHP Debug extension. It seems that Visual Studio Code is at least getting XDebug to begin listening on port 9000, but for whatever reason it isn't progressing as expected.
So I ended up getting it to work by following this video: https://www.youtube.com/watch?v=a14kN2u5nEk by Lyall van der Linde. Among other mistakes, I shouldn't have configured both the service and the extension to the same port.
A little quirk at this time is as far as I can tell that XDebug doesn't have a release currently for PHP 32 bit version 7.3.1 so I ended up installing an old version of XAMPP (7.2.14). Old versions of the Windows installer are available at https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/. I have installed the most recent version of Visual Studio Code. I've added the PHP Debug extension to Visual Studio Code and reloaded the application.
Since IIS is using port 80, I opened XAMPP Control Panel and navigated to the master level Config, then Service and Port Settings and set, under the apache tab, the Service Name Apahce2.4 to Main Port 8080 and SSL Port 443. I edited C:\xampp\apache\conf\httpd.conf and replaced "Listen 80" with "Listen 8080". Then I started the apache service in the XAMPP Control Panel.
I then added the folder "phptest" under C:\xampp\htdocs\ and opened said folder in VSCode. Added File test.php and added lines:
<?php
$a = 6;
$b = 3;
$c = 0;
$c = $a * $b;
echo $c;
I updated the VSCode User Settings as follows
{
"php.validate.enable": true,
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
"php.validate.run": "onType"
}
I opened the output of http://localhost:8080/phptest/test.php as “18”.
I opened http://localhost:8080/dashboard/phpinfo.php, copied the text of that page and pasted the results to the input form at https://xdebug.org/wizard.php. This prompted me to download the correct dll for XDebug (php_xdebug-2.6.1-7.2-vc15.dll for me). I then edited C:\xampp\php\php.ini and appended to the end of the file:
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = C:\xampp\php\ext\php_xdebug-2.6.1-7.2-vc15.dll
Due to the changing php.ini, I needed to stop and restart the Apache service in the XAMPP Control Panel. I then selected "Debug" under the left navigation of Visual Studio Code and added a PHP configuration "Listen for XDebug" and used the default 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": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I added a breakpoint in test.php and started debugging in Visual Studio Code. I navigated in my browser to localhost:8080/phptest/test.php and my breakpoint was hit in Visual Studio Code allowing me to view the values of variables and step through the code.
I am trying to run PHP code on Microsoft VS Code. When I click launch the only thing that happens is an error in the debug console saying:
spawn php ENOENT
To fix this, I have put the dll file for XDebug into the ext folder. I copied php.ini-development into a new file called php.ini and in that file I added this to the end of the file.
zend_extension="[file path]"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
This changed nothing.
Then, I added an inbound rule for my firewall to allow inbound connections on port 9000. Still, nothing changed. How can I fix this?
What fixed it for me, was adding this line to user settings:
"phpserver.phpPath": "c:\\Ampps\\php-7.1\\php.exe"
Your path may vary. (-> error occurs, because your php is not found)
phpserver: This is because I use the PHP Server extension. If you use a different extension, you need a different parameter.
I am using the PHP_DEBUG extension and with a portable laragon environment.
I had to make this change to my workspace settings / user settings
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"runtimeExecutable":"D:\\Share\\Dev\\Laragon\\bin\\php\\php-7.3.10-Win32-VC15-x64\\php.exe",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
Basically I had to add the runtimeExecutable line as defined by the PHP_debug extension.
I used this guide to get working with vscode + xdebug + laragon
However I still have an issue, when running individual scripts, that the environment and extensions aren't properly loaded for the CLI
For PHP-Debug users with similar issue:
Having worked for a long time, this stopped working for me recently (Oct 2021).
Usually within the SPAWN ENOENT error it will show the path it has set for PHP.
Although correct location was in PATH environment variable (which is used by default in the PHP-Debug extension), it was still giving error.
If you set the runtimeExecutable in settings explicity, that also failed.
The only thing that worked for me was to set the runtimeExecutable to simply "PHP".
One cause for this error could be a missing launch configuration in VS Code. You may try to add a launch.json in directory .vscode.
Here is the one I am using.
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003
}
]
}
I fixed the issue by setting the working directory. Seems to need to be set each tab.
I had the same problem using VsCode with XAMPP in ubuntu - linuxmint.
This VSCode settings were not working:
"php.debug.executablePath": "/usr/bin/php",
"php.validate.executablePath": "/usr/bin/php"
The reason in my case was that /usr/bin/php is a symbolic link to /opt/lampp/bin/php, and it seems that VSCode doesn't like it.
I got the solution changing the path to the original php executable in XAMPP:
"php.debug.executablePath": "/opt/lampp/bin/php",
"php.validate.executablePath": "/opt/lampp/bin/php"
Hope it helps.