Unable to get Xdebug to work on VSCode with browser extension - php

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..

Related

Setup Xdebug configuration for PHP scripts called in cron by docker-entrypoint.sh in VSCode

Currently using VSCode on MacOS, Xdebug is working well for my PHP web application ran with docker.
But I also have some PHP scripts that are called by the docker-entrypoint.sh as crons and I'd like to be able to debug them as well. I can't configure it properly, nothing happens when I set breakpoints while the crons are running.
Here is my launch.json configuration at the moment (all the codesource - web, scripts...- is under myapp/app) :
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9001,
"log": true,
"pathMappings": {
"/opt/myapp/app": "/Users/me/src/myapp/app"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9002,
"log": true
}
]
}
In my docker-compose.yml, I also have PHP_XDEBUG_ENABLED=true for the web container and the cron container of course.
Any ideas / configuration examples to get the debug working for the PHP crons ?

Xdebug is successfully installed on Windows but not working

I downloaded the dll file by copy-pasting the phpinfo() output to Xdebug site, so I think I got the right file.
I edited my php.ini file and restarted Apache web server (I'm using XAMPP).
I set breakpoints, hit "Add Configuration" and Run the debug in Visual Studio Code.
Unfortunately, the breakpoint did not worked.
I have gone through many topics, tutorials but it still not works.
This is how my php.ini file looks like:
[XDebug]
zend_extension = "D:\xampp\php\ext\php_xdebug-3.0.4-8.0-vs16-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
This is my config file:
{
// 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
},
{
"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}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
This is the image I took using the xdebug_info();
Your help save my day.
Your screenshot shows that you don't have the Step Debugger enabled (it says "Disabled").
Your config says:
zend_extension = "D:\xampp\php\ext\php_xdebug-3.0.4-8.0-vs16-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
Xdebug 3 does no longer use xdebug.remote_enable or xdebug.remote_autostart. As per the Upgrade Guide these have been renamed to:
xdebug.mode=debug
xdebug.start_with_request=yes
The "Docs" column in your screenshot also links to the documentation for that specific feature.
My solution after trying the instruction with windows and xampp:
Just download the xdebug extension again and do the instructions!

Xdebug is working but not stopping at breakpoints in VSCode

I'm using XAMPP and have installed Xdebug from Xdebug Wizard page, but renamed php_xdebug-3.0.2-7.2-vc15-x86_64.dll to php_xdebug.dll
My php.ini:
[XDebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
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": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I have this extension installed:
When run I get this output in the console:
When I set the listen Xdebug:
And open the program it goes trough the breakpoint:

XDebug not working in VScode for php debugging

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

How to PHP debug multiple websites in VS Code

Expected behavior:
I have multiple PHP projects on different servers, usually I debug them with PhpStorm which allows me to configure path mappings for remote debugging per server. Thus I can have the same remote paths e.g. /var/www/html for different servers.
Problem description:
So far I have been unable to configure multiple servers with the same remote paths using VSCode.
I use the most used php-debug plugin for VSCode and have not found any information regarding this issue on the projects GitHub page or anywhere else.
Currently I do not think configuring multiple remote servers using VSCode is possible at this time but in case someone knows a way I would appreciate it.
Current configuration:
With the following configuration I can only debug one project at once and have to change the paths manually when I want to debug another project on another server with the same remote paths.
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path",
"/var/www/html/src/shared:": "/local/shared/src/path",
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Step 1
To debug multiple websites with VSCode first add multiple configurations to the vscode-php-debug extensions config (Run->Open Configurations) with different names.
{
"version": "0.2.0",
"configurations": [
{
"name": "website 1",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path1",
}
},
{
"name": "website 2",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path2",
}
},
{
"name": "website 3",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path3",
}
},
]
}
Step 2
You then have to select the appropriate configuration before debugging your code by clicking on the current configuration in the bottom left hand corner or writing debug in the top bar (ctrl+t and remove the hash) (which will make that configuration the default for the current session and immediately launch debugging).

Categories