First, I'm very new to PHP. I'm trying to use the PHP Debug extension in VS Code with PHP Version 8.0.2 and Xdebug Version 3.0.2.
I've switched the Apache ports to 9000/90001. Everything seems to work correctly in the browser when I navigate to localhost:9000/test.php. However, when I try to debug in VS Code, the breakpoints are never triggered.
My PHP.ini Xdebug section:
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug-3.0.2-8.0-vs16-x86_64.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.idekey = VSCODE
xdebug.remote_host=127.0.0.1
xdebug.default_enable=1
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "c:\xampp\tmp"
xdebug.remote_handler = "dbgp"
xdebug.remote_log = "c:\xampp\tmp\xdebug.txt"
xdebug.trace_output_dir = "c:\xampp\tmp"
xdebug.remote_cookie_expire_time = 36000
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": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "",
"cwd": "",
"port": 9000
},
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
}
]
}
Any help here would be greatly appreciated!
Your configuration contains mixed statements from different XDebug versions (v2.x and v3), while your XDebug extension looks to be v3. Please take a look at the following guide to understand which configuration should belongs to v3:
https://xdebug.org/docs/upgrade_guide
I have succeeded with this config using v3:
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host=192.168.1.3
xdebug.client_port=9000
xdebug.log=/tmp/xdebug.log
Related
My php.ini configuration:
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.mode = debug
xdebug.remote_autostart = on
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/xampp/tmp"
xdebug.show_local_vars=0
xdebug.remote_host = 127.0.0.1
xdebug.remote_enable = 1
xdebug.remote_port = 9003
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.remote_autostart=1
xdebug.idekey=PHPSTORM
xdebug.remote_log="c:/xampp/tmp/xdebug.log"
My launch.json configuration:
{
// 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": 9003
}
]
}
but i am still getting this error in error.log:
[php:notice] [pid 9388:tid 1840] [client ::1:63322] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(, referer: http://localhost/online-store/admin/types/insert-types.php
First I used the port 9000 but it didn't work, then I tried changing the port in php.ini and launch.json to 9003 same as the port in error log but still nothing is happening and XDebug is not working and not stopping on breakpoints.
I also encountered with such an error after updting my Xdebug library to 3+ version.
What I found out is that new setting xdebug.start_with_request = yes configures Xdebug to establish a connection on every request.
Meanwhile the official doc offers to use xdebug.start_with_request = trigger in order to connect Xdebug only if the need for it was explicitly indicated. In this case I can start step debugging process with passing an extra key via GET parameters, for example http://localhost/?XDEBUG_TRIGGER=1, but this is inconvenient for me, all I want is press F5 within my VSCode to start debugging as I always did.
So my solution is the following. I left start_with_request = yes and turned off most of Xdebug notifications by passing xdebug.log_level = 0. Then i override log_level within launch.json file to enable all warnings but only within debugging session.
php.ini:
[XDebug]
zend_extension = php_xdebug-3.0.4-7.4-vc15-x86_64.dll
xdebug.mode = debug,develop
xdebug.discover_client_host = yes
xdebug.log_level = 0
xdebug.log = "%sprogdir%/userdata/temp/xdebug/log.txt"
xdebug.start_with_request = yes
xdebug.idekey = VSCODE
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"env": {
"XDEBUG_CONFIG": "log_level=7",
}
}
]
}
I encountered the same issue with PHP8. In my case, it was just the XDebug version suggested by their own wizard.
I use this version and it works just fine.
3.0.0-8.0-vs16
launch.json:
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"hostname": "localhost",
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www/"
},
},
change pathmappings according to your requirements and the most important is hostname. after i added that, it worked
I have installed Xdebug with VS Code and Flywheel local and I am learning how to make themes. I have put a breakpoint in my index.php file. However, the said breakpoint is not working.
I am not getting any errors in my console. Nothing is happening in VS Code debug terminal when I load my site. It's just all blank. I have also installed PHP Debug extension in VS Code.
However, when I type in debug console anything I get this message - Cannot evaluate code without a connection.
What went wrong here?
My php.ini
[xdebug]
{{#if os.windows}}
zend_extension = php_xdebug.dll
{{else}}
zend_extension = {{extensions.xdebug}}
{{/if}}
xdebug.remote_enable=1
xdebug.remote_connect_back=Off
xdebug.remote_port="9000"
xdebug.profiler_enable=0
xdebug.remote_autostart = 1
xdebug.mode=debug
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,
"pathMappings": {
"C:/Users/ajayb/Local Sites/wordpress-theme-1/app/public": "${workspaceRoot}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I have faced the same problem. Local by FlyWheel installs Xdebug 2.7 for PHP 7.3 and XDebug 3.x when using PHP 7.4. If you are using PHP 7.4 modify the php.ini file and replace the xdebug section with the following:
[Xdebug]
; Consider checking php_xdebug.dll file properties to get installed Xdebug version
zend_extension="D:\Programs\xammp\php\ext\php_xdebug.dll"
; Settings for Xdebug 2.x
xdebug.scream = 1
xdebug.remote_enable = 1
xdebug.show_local_vars = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
; Settings for Xdebug 3.x
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port="9000" ; Default now is 9003
Even if you have XDebug's version 2.x.x, the default configuration is not enough.
You have to use the following for Xdebug v2.x.x:
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
Yeap, as it was mentioned in a comment the main reason is https://xdebug.org/docs/upgrade_guide
I had the same issue with PHPStorm & Flywheel Local app v6+.
I set PHP 7.4.1 in Local and found in ~/projects/project-name/conf/php/php.ini.hbs next v2 options:
xdebug.remote_enable=1
xdebug.remote_connect_back=Off
xdebug.remote_port="9000"
xdebug.profiler_enable=0
But when I checked var_dump(phpversion('xdebug')); it ouptuted XDebug 3. It worked for me with v3 options:
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_port="9003"
xdebug.discover_client_host=0
My problem was that i wasnt changing the php.ini in the right place.
There is a general conf\php folder and there are version specific ones.
Changing php.ini xdebug settings in conf\php solved it.
Also i put the full path in the pathmappings(launch.json) like so:
"pathMappings": {
"C:\\Users\\Test\\Local Sites\\localtest\\app\\public": "${workspaceFolder}",
}
I have recently installed php debugger by Felix Becker.
No matter whatever config settings I do, my debugger is not hitting anything.
Following are my conf files.
xdebug.ini
[xdebug]
; debug
xdebug.default_enable = $value
xdebug.remote_autostart = $value
xdebug.remote_connect_back = 0
xdebug.remote_host = $value
xdebug.remote_port = $value
xdebug.remote_enable = 1
xdebug.idekey = $value
; profiling
xdebug.profiler_enable = 0
xdebug.profiler_output_dir = /tmp
zend_extension=xdebug.so
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": 9009,
"pathMappings": {
"path/path": "$value"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9009,
"pathMappings": {
"path/path": "$value"
}
}
]
}
Am I missing anything here ?
Xdebug v3.0.1, by Derick Rethans
You are using Xdebug v3 but keep using Xdebug v2 config parameters. You need to go through Upgrading from Xdebug 2 to 3 Guide and adjust your settings (mostly just change the parameter name).
Xdebug v3 uses different config params than Xdebug v2. From what I see 8 out of 9 "xdebug." params from your current php.ini do nothing in Xdebug v3.
For Xdebug 3 it should be something like this (based on your original config):
zend_extension=xdebug.so
[xdebug]
xdebug.mode = debug
; for profiling switch to below:
;xdebug.mode = profile
xdebug.client_host = ${PHP_XDEBUG_REMOTE_HOST}
xdebug.client_port = ${PHP_XDEBUG_REMOTE_PORT}
xdebug.discover_client_host = false
xdebug.start_with_request = ${PHP_XDEBUG_REMOTE_AUTOSTART}
xdebug.idekey = ${PHP_XDEBUG_IDE_KEY}
xdebug.output_dir = /tmp
P.S. xdebug.discover_client_host will now fallback to xdebug.client_host on failure (unlike v2 that would try autodetected host only).
P.P.S. xdebug.default_enable = 1 is replaced by xdebug.mode = develop. If you need that then you can list multiple values via comma, e.g. xdebug.mode = develop,debug
A fix for Becker extension was pushed in v1.52.1, see https://github.com/microsoft/vscode/issues?q=is:issue+milestone:%22November+2020+Recovery%22+is:closed
The php debugger extension by Felix Becker is using previously-deprecated api and so the last vscode version 1.52 means it won't hit breakpoints. There are many issues on vscode's github on this. A vscode team member suggests enabling this setting to fix:
Debug: Allow Breakpoints Everywhere
see https://github.com/microsoft/vscode/issues/112288#issuecomment-743456329
The other option is to use a different extension which has updated its code to accommodate the deprecations. For examples, see https://github.com/felixfbecker/vscode-php-debug/issues/424#issuecomment-727932756
working on ubuntu 19.10 and trying to get started with debugging my code in VScode, but after installing an extension - nothing works(buttons are disabled).
Using php7.3, in php.ini added several lines:
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_port=9000`
apache2 installed, but for now use build-in web server
my php.ini config sees the params i've added also.
the .json file VScode made itself is:
"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
}
]}
Use this configuration
zend_extension=<path_of_the_extension>
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.idekey = VSCODE
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.remote_log=/var/log/apache2/xdebug.log
xdebug.remote_timeout = 500
Also be sure that the php.ini file is the right one, using phpinfo(); function. The first lines show the path
phpinfo()
PHP Version => 7.4.7
...
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
...
In my case, this configuration was written in /etc/php/7.4/mods-available/xdebug.ini instead of the php.ini because XDebug was installed in Ubuntu from repositories
I am trying to create a new report for my job's database.
Attempting to debug PHP in VSCode on Windows 10, running XAMPP on the local machine.
The site is in vue.js with a php api connecting to mysql 5.7 database. I use npm run dev for the crm in \khcc2\NETFOLDERS\UserName\htdocs\crm and need to debug the report.class.php api.
In php.ini
[XDebug]
zend_extension = C:\tempx\xampp\php\ext\php_xdebug-2.7.1-7.3-vc15-x86_64.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = localhost
xdebug.idekey = "vscode"
xdebug.remote_port = 9000
In the api I have launch.json
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
}
I've tried adding to the launch.json each of these (not all at once):
"cwd": "\\\\khcc2\\NETFOLDERS\\UserName\\htdocs\\api",
"cwd": "h:\\htdocs\\api",
"cwd": "${workspaceRoot}",
and I sill get:
Unable to open 'index.php': File not found (file:///h:/htdocs/api/NETFOLDERS/UserName/htdocs/api/index.php).