I have a problem with PHP Xdebug on VSCode.
My environment is Windows Server 2012 R2, I have installed VSCode and running IIS server with PHP 7.4, with Xdebug 3
When I open script with xdebug_info() from Firefox, then Xdebug log produces output. But when I hit F5 in VSCode there's no output (seems like extension doesn't connect with Xdebug at all).
VSCode config (it's default):
{
// 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,
"log": true,
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003,
}
]
}
php.ini:
[XDebug]
zend_extension = "c:\Program Files\PHP\v7.4\ext\php_xdebug-3.0.4-7.4-vc15-nts-x86_64.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host=::1
xdebug.log = "c:\inetpub\xdebug_log.log"
VSCode debug output:
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true
}
But I don't see any variable's values at all. Breakpoints doesn't work too.
When I try to call something in debug console, the output is:
Cannot evaluate code without a connection
Which could be inferred from no-log entries produced by VSCode requests. I spent about 4 hours about googling this problem, but couldn't find solution.
Related
Going round and around in circles on this one.
With a local install xampp setup I can get PHP-DEBUG working just fine in both standard modes:
"Listen for XDebug" and
"Launch currently open script"
Trying to move this to a remote machine - specifically a Synology NAS.
In VS Code, I can connect the folder via a standard SMB path, e.g.:
//[nas]/web/[project]
In localhosts I have mapping to the site and this is managed via virtualhost in Synology DiskStation and this works fine, e.g.
10.x.y.z dev.mysite.com
I'm trying all manner of things suggested on setting hostname, pathmappings, xdebug.remote_host (set to NAS IP), xdebug.idekey (VSCODE), xdebug.remote_connect_back (ON) etc but really not getting anywhere- latest dead end is an error:
message: 'listen EADDRNOTAVAIL: address not available 10.x.y.z:9001'
NB - Using port 9001 to avoid conflict elsewhere...
launch.json as below - where am I going wrong?
{
// 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",
"hostname": "dev.mysite.com",
"port": 9001,
"pathMappings": {
"/": "${workspaceFolder}"
},
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"hostname": "dev.mysite.com",
"port": 9001,
"pathMappings": {
"//[nas]/web/[project]": "${fileDirname}"
},
"log": true,
}
]
}
Help.....
"xdebug.remote_host (set to NAS IP),"
No. That is always wrong. The xdebug.remote_host (now xdebug.client_host in Xdebug 3) needs to point to the machine where your IDE runs at. It is Xdebug that makes the connection.
Also, these settings do nothing for Xdebug 3, which is the latest (and only supported) version. Please read the Upgrade Guide.
I'm trying to setup Xdebug on my VSCode, to do so I installed the PHP Debug extension and set the launch.json as so :
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"stopOnEntry": true,
"pathMappings": {
"/Users/me/Desktop/www/my_current_project": "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
For the extension on chrome I use Xdebug helper, and I'm not sure if it's supposed to work without cookie or not in the case of VSCode (because PHPStorm needs one), but I've set the cookie value to "VSCODE" as I found somewhere on the internet...and the extension is enabled (green).
Then, I clicked on "Listen for Xdebug" on VSCode, and set some breakpoints on my script, but VSCode does not respond to me calling the script from the browser.
I have not found so far any solution that worked for me, I guess there's an issue in the launch.json file maybe..
Given this setting in my vscode
{
// 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,
"hostname":"::1",
"pathMappings": {
"/var/www/html/": "${workspaceRoot}/item-street"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"hostname": "::1",
"port": 9003
}
]
}
and xdebug.ini
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_port=9003
xdebug.discover_client_host=1
This xdebug configuration is located in /etc/php/8.0/mods-available/ in WSL2 Ubuntu-20.04
following the setting here
https://github.com/felixfbecker/vscode-php-debug
But adding break point on php code and pressing f5, and visit the local php project in chrome
just nothing happen.
I did also read the following
Setting up VSCode with xdebug: pathMapping
VSCode - XDebug connected to client but break points does not work
but seems doesn't work to my case.
Do you know why?
previously its fine but now it's not
Just found an answer myself. On VSCode click the remote explorer not sure if this is really part of it and next install PHP debugger extension on Google Chrome.
Put a break point on PHP file, click PHP debugger on chrome, press f5 on VSCode, and it worked.
Edit:
My initial statement works, but not really the answer.
The actual answer is the https://github.com/felixfbecker/vscode-php-debug only support port:9000 or it's just xdebug the only support port 9000.
So instead of
xdebug.client_port=9003
Set it as
xdebug.client_port=9000
PHP debugging in vscode using xdebug and xampp is not working even after all configurations.
here is my php.ini file config:
zend_extension = D:\Xampp\php\ext\php_xdebug-3.0.0-7.3-vc15-x86_64.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
this is json file
{
"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}"
}
]
}
xDebug 3 has changed several default values, so be sure your code is ready to work with new ones.
Here is my configuration set, which allowed me to use PHP breakpoints as always:
.vscode\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
}
]
}
php.ini (lines manually inserted in the end of a file)
[xdebug]
zend_extension = "php_xdebug-3.0.4.dll"
xdebug.mode = debug
xdebug.discover_client_host = 1
xdebug.start_with_request = yes
xdebug.client_port = 9000
Note: above zend_extension option would try to find your xdebug library in a .../modules/php/PHP_%your_php_version%/ext/ folder
I just got satisfaction with XDebug 3.
I found a good response here :https://github.com/felixfbecker/vscode-php-debug/issues/411 by jason-nabooki.
I do the same :
Json file :
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"stopOnEntry": true,
"log": true,
"pathMappings": {"/var/wwww/ammac":"${workspaceRoot}"}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003
PHP.ini :
xdebug.mode= debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
To use the debugger (I didn't find immediatly due to my precedent use of Eclipse !),
first : click on the green triangle near "Listen for XDebug
second : refresh the web page in Firefox (or other)
For me it works i got the variables. Not yet test the breakpoints.
Remark : no need of the XDEbug helper in Firefox (surprise!)
In VSCode, I went to Settings -> Features -> Debug -> Allow Breakpoints Everywhere.
I check marked "Allow Breakpoints Everywhere" and I was able to debug again.
Struggled with this myself. Apparently XDebug 3.x doesn't work as outlined above. I found that even the equates under [XDebug] are no longer compatible. Download XDebug 2.x (I think 2.98 is the latest in the 2.x series). After I switched to 2.x, I'm no longer having any issue (so far).
https://xdebug.org/wizard - This tool helped me to find the reason why debuger didn't work.
Your are using xdebug version 3:
zend_extension = ... php_xdebug-3....
but in configuration you listen port 9000:
"port": 9000
The default Xdebug port changed between Xdebug v2 to v3 from 9000 to 9003.
Just change "port": 9000 => "port": 9003
I'm trying to debug my php with wamp, xdebug and this extension, but I can't get it to work. This is the end of my php.ini (C:\wamp64\bin\php\php7.0.4\php.ini):
[Xdebug]
zend_extension ="C:/wamp64/bin/php/php7.0.4/ext/php_xdebug-2.4.1-7.0-vc14-x86_64.dll"
xdebug.remote_enable=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir ="c:/wamp64/tmp"
My launch.json (C:\wamp64\www\CubePicker.vscode\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
}
]
}
Settings.json:
// Place your settings in this file to overwrite the default settings
{
"emmet.syntaxProfiles":
{
"php": "html"
},
"php.validate.executablePath": "C:/wamp64/bin/php/php7.0.4/php.exe",
}
Can anyone see what I am doing wrong? I launch the debugger in VS Code, then run the webpage through my browser, which I assume is correct...? How can I fix this and make it hit the breakpoints I put in?
Let me know if you need anything else.
Thanks!
[EDIT]: I have been into phpinfo(), found the path of the loaded php.ini, and edited it to add the first chunk of code. This didn't fix the problem.
[EDIT]: I have also copied the whole of my phpinfo() here: http://pastebin.com/4Jk5TuQj
Author of the extension here.
As stated in the readme, you need to add
xdebug.remote_autostart = 1
to your php.ini so XDebug will actually make a request to VS Code.
I also searched your phpinfo() output but there was no XDebug section.
You should use the XDebug config wizard here: xdebug.org/wizard.php