Cannot debug php line by line in vscode - php

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

Related

Listen for XDebug php in vscode with xampp

Once I performed all the configuration stuff, downliading the .dll, adding it to the ext path in xamp and to the php.ini etc.
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9003
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
After adding both configs in vsCode:
1.- Installing the php debug extension
2.- Run->AddConfiguration->Listen for Xdebug
3.- Run->AddConfiguration->"Launch currently open script"
So both debug modes seem to be possible:
Surprisingly I can make the debug work if I "Launch currently open script".
De default config for the "Launch currently open script" is:
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
},
}
But that did not work until I added runtimeExecutable":"C:\\xampp\\php\\php.exe.
For the case 1.- Listen for Xdebug, that is to debug the whole app without the need of selecting an specific file, I could not make it work. The launch.json is:
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
I tried of course adding the runtimeExecutable":"C:\\xampp\\php\\php.exe, changing the ports, restarting apache and vs code and adding to de vs code settings the Allow Breakpoints Everywhere checkbox.
I am close, because for Launch current script mode works but when I launch vscode with the Listen for Xdebug option, my breakpoints are in place and my page is reloaded for check. Nothing happens and there are no errors in the vscode debug console.
Any idea of what needs to be done for the Listen for Xdebug to work and be able to debug the whole proyect with vscode?
Edit:
I also tried adding this options to my php.ini:
xdebug.mode = debug
xdebug.discover_client_host = 1
xdebug.start_with_request = yes
as recommended here
and the visualStudio php configuration Listen for XDebug 2 (Legacy)
Followed the intructions from the extension docs and I dont find what is wrong.

PHP Xdebug Doesn't work in VSCode - Windows + IIS

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.

How do I set up VS CODE PHP-DEBUG on a (Synology) NAS? / remote device

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.

How do I install xdebug extension for chrome or firefox Offline?

I am beginner in cakePhp I have two computer. one which is connected to the Internet I can debug but another which is not connected I can't debug
I install xdebug extension locally.
even I installed xdebug for chrome locally
But I can't debug my website which is a cakephp website
In php.ini configuration of x-debug section is:
[X-Debug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = D:\wamp64\bin\php\php7.2.18\ext\php_xdebug-2.9.1-7.2-vc15-x86_64.dll
All condition is the same between two computers the only different is version of google one of them is which is connected to Internet is 79.0.3945.130 and another is 74......
with chrome I installed extension but with fireFox I couldn't install edebug extension.
Can anybody help me how can I debug with vsCode locally?
Best Regards
The key point that I can debug cakePHP in vsCode offline is .vsCode folder in first level of cake site and inside it in launch.json file there is one line which is: "name": "Listen for XDebug", is the reason that you can debug in offline status,but how I have .vsCode folder I follow this link:
Xdebu Installation Wizard
{
// 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
}
]
}
Other necessary step is putting the appropriate dll (php_xdebug-2.9.1-7.2-vc15-x86_64.dll) in this folder:
D:\wamp64\bin\php\php7.2.18\ext which is the extension folder of my active php

Can't debug php with VS Code

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

Categories