I am using Visual Studio Code and Xdebug is by default installed in it with version v3.x.x.
Sharing configuration below,
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9001,
"stopOnEntry":true,
"log": true,
"hostname": "localhost",
"pathMappings": {
"/var/www/html": "${workspaceRoot}",
"/app": "${workspaceRoot}/app"
}
}
]
}
php.ini,
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
test.php
<?php
echo "<script>alert('Welcome');</script>";
phpinfo();
?>
Now when I start the debugger at port 9001 on my local host (note no remote hosting is there). And on accessing it via, http://localhost:9001/test.php
It gives following comments on Debug console,
new connection 1
new connection 2
It gets started, but for some strange reason gives me, two new connection and they are printed only after I have access it via browser.
Now I wait for 5-10 seconds (meanwhile, browser keep loading, but nothing is visible and its still attempting to access test.php) I have placed Debugger point on all lines.
And suddenly after 10 seconds, its closes connection with below comments,
<- outputEvent
OutputEvent {
seq: 0,
type: 'event',
event: 'output',
body: { category: 'console', output: 'connection 2 closed\n' }
}
connection 2 closed
<- continuedEvent
ContinuedEvent {
seq: 0,
type: 'event',
event: 'continued',
body: { threadId: 2, allThreadsContinued: false }
}
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 2 }
}
<- outputEvent
OutputEvent {
seq: 0,
type: 'event',
event: 'output',
body: { category: 'stderr', output: 'connection closed\n' }
}
**connection closed**
I have checked everywhere, but unable to to find answer to my problem. Request for help
Finally I was able to start Xdebug with Visual Studio code on XAMPP server. I am sharing my solution so that others don't face similar issues.
Install XAMPP on Ubuntu
Configure it to route it to code outside htdocs folder
Follow this link, https://askubuntu.com/questions/64095/change-xampps-htdocs-web-root-folder-to-another-one
Create index.php file and run,
phpinfo();
open browser and execute localhost/index.php
Copy the text to https://xdebug.org/wizard
The resultant will be a page with list of instrcutions, just follow them one by one and make sure Xdebug is successfully installed on Ubuntu
Now the important piece, open file /opt/lampp/etc/php.ini (I was trying to configure my local Laravel php.ini in my code, that's where its failing to recognize)
and paste following commands,
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host = localhost
zend_extension = "/opt/lampp/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so"
Now go Visual Studio Code and open apply debugger points on your index.php
If running and debugging is not yet configured (no launch.json has been created), VS Code will show that and you can configure it by Running. Leave launch.json settings default.
Go to Run --> Start Debugging -> "Listen for Xdebug" and configure same for PHP for first time.
That's it !
Related
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
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.
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 setup xdebug to work with sublime text 3 on my WAMP server. The problem is, that when I go to:
Tools -> XDebug -> Start Debugging (Launch Window)
The window it launches is localhost/nutri/ every time. This is a problem because I might need to debug localhost/nutri/other_page.php so I do this:
Tools -> XDebug -> Start Debugging (Launch Window)
So for example, say I need to launch the debugger on localhost/nutri/otherpage.php
but it opens the browser on the page:
http://localhost/nutri/?XDEBUG_SESSION_START=sublime.xdebug
So the xdebug is configured right I think:
enter link description here
Heres from php.ini:
; XDEBUG Extension
[xdebug]
zend_extension = "c:\\wamp\\bin\\php\\php5.6.19\\zend_ext\\php_xdebug-2.4.1-5.6-vc11.dll"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_log= "C:\\wamp\\tmp\\xdebug.log"
xdebug.profiler_enable=0
xdebug.profiler_output_dir = "C:\\wamp\\tmp"
xdebug.collect_params = 4
xdebug.collect_return = on
xdebug.collect_vars = on
xdebug.show_local_vars = 3
Heres my sublime text project file:
{
"folders":
[
{
"path": "test",
"follow_symlinks": true,
},
{
"path": "wp-content\\plugins\\genomics",
"follow_symlinks": true,
},
{
"path": "wp-content\\plugins\\decodify-members",
"follow_symlinks": true,
},
{
"path": "wp-content\\plugins\\decodify-terminology",
"follow_symlinks": true,
},
{
"path": "wp-content\\themes\\decodify",
"follow_symlinks": true,
}
],
"settings":
{
"xdebug":
{
"url": "http://localhost/nutri/"
},
"sublime-view-in-browser": {
"baseUrl": "http://localhost/nutri",
"basePath": "C:\\wamp\\www\\nutri"
}
}
theres nothing really interesting in the XDebug config file:
// Example:
// "/absolute/path/to/file/on/server" : "/path/to/file/on/computer",
// "/var/www/htdocs/example/" : "C:/git/websites/example/"
"path_mapping": {
},
// Determine which URL to launch in the default web browser
// when starting/stopping a session.
"url": "http://localhost/nutri/",
// An IDE key is used to identify with debugger engine
// when Sublime Text will start or stop a debugging session.
//
// This package does not filter sessions by IDE key,
// it will accept any IDE key, also ones that do not match this configured IDE key.
// It is merely used when launching the default web browser with the configured URL.
"ide_key": "sublime.xdebug",
// Which port number Sublime Text should listen
// to connect with debugger engine.
"port": 9001,
// Show super globals in context view.
"super_globals": true,
// Maximum amount of array children
// and object's properties to return.
"max_children": 32,
// Maximum amount of
// variable data to initially retrieve.
"max_data": 1024,
// Maximum amount of nested levels to retrieve
// of array elements and object properties.
"max_depth": 1,
Is there a way to add a page variable to the path that xdebug uses to load pages?
EDIT:
I managed to get the keyboard shortcut to start the debugger and run the browser at the same time by adding this keybinding to my sublime.keymap file:
{
"keys": ["ctrl+shift+1"],
"command": "xdebug_session_start",
"args": {
"launch_browser" : true
}
}
Which helps a lot, but I still can't figure out how to make it launch the right file. It always launches whats in my project file:
"xdebug":
{
"url": "http://localhost/nutri/"
}
which is the root page of my website. Is there a way I can add a variable to it like:
"url": "http://localhost/nutri/{$file}"