Xdebug in Laravel is not working with VSCode - php

I'm trying to debug a Laravel project in Ubuntu 20.04. There is a problem that debugger doesn't hit breakpoint just in Laravel project but in other projects Xdebug works correctly.
PHP 7.4.3
Xdebug v2.9.2
my lunch.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,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"log": true
}
]}
and my php.ini:
zend_extension=”/usr/lib/php/20190902/xdebug.so”
xdebug.profiler_enable_trigger=0
xdebug.profiler_enable=0
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_log="/tmp/xdebug.log"
xdebug.remote_enable=1
xdebug.remote_autostart=1
and my laravel.env:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:foo...
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack

I was in the same situation as you, and I found a solution.
Install VScode Xdebug extension
sudo apt install -y php7.4-dev php7.4-xdebug (Install Xdebug 3.*)
Set xdebug.ini
zend_extension=xdebug.so
xdebug.mode = debug
xdebug.remote_autostart = 1
; This is correct option for xdebug 3!!!
; Don't use xdebug 2 option!!!!
xdebug.client_host = localhost
xdebug.client_port = 9003
xdebug.log = /tmp/xdebug_remote.log
xdebug.log_level = 7
xdebug.start_with_request = yes
Set port 9003 in launch.json
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true
},
Restart php and webserver.
Check whether xdebug is installed with phpinfo();
Make test controller, route for debugging
You don't need to edit php.ini
I still don't know much about Xdebug, but I think
xdebug.start_with_request = yes is the most important.

Related

Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003

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

How could I let Xdebug steping over the code

I have been working with Laravel version 7 with php7.4 and suddenly my Xdebug is not steping over the lines but before is working fine and I don't change or touch any configuration file.
vscode configuraion
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"stopOnEntry":false
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
php.ini
[XDEBUG]
xdebug.mode=debug
;my-updates
xdebug.remote_autostart=1
xdebug.default_enable=1
xdebug.remote_port=9003
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
;end
zend_extension = C:\xampp\php\ext\php_xdebug-3.0.1-7.4-vc15-x86_64.dll
and extension
PHP Debug felixfbecker.php-debug v1.14.9
so when I set breakpoint on a line its cache but is not step over the lines also I set many breakpoints and press button debug called continue also is jump to this function
public function prepareResponse($request, $response)
{
return static::toResponse($request, $response);
}

Cannot setup Xdebug in VSCode on XAMPP on Linux Mint

Here is my setup:
php.ini in xampp in found: /opt/lampp/etc/php.ini
[XDebug]
zend_extension=/usr/lib/php/20180731/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
This is what the phpinfo() looks like:
I am not able to step through the code or even set a breakpoint using the recommended PHP Debug plugin.
This is the default launch.json for VSCode.
{
"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 saw in your phpInfo() ss that the port for xdebug is set to 9003 while your launch.json is listening to port 9000. Maybe this is the problem?

VS Code not stopping at breakpoint with PHP XDebug

i'm working in Laravel application, i'm trying to use XDEBUG with WAMP Server and Visual Studio code, when i run "Listen for XDEBUG" in VS code it dosen't stop at break point but the page still in charge it's like the debug is working but not stopping in breakpoint.
I already have added XDEBUG's extension in Chrome
Here's my Lanch.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": 8000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
And in my php.ini i have this at the end :
[xdebug]
zend_extension="c:/wamp64/bin/php/php7.2.25/zend_ext/php_xdebug-2.8.0-7.2-vc15-x86_64.dll"
xdebug.remote_enable =1
xdebug.profiler_enable =1
xdebug.profiler_enable_trigger =1
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0
xdebug.default_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=8000

Xdebug on Vagrant Scotchbox running PHP 7.2 - Config

Not a question, but wanted to share with you the config i've used to get xDebug working on Vagrant using Scotchbox with PHP 7.2.
I had issues getting xDebug working with scotchbox and found many pother articles providing suggested configuration but none worked for me.
This was my process:
vagrant ssh
sudo pecl install xdebug. if errors read the advice given.
it says to add ../xdebug.so" to php.ini. copy this line, ie:
zend_extension=/usr/lib/php/20170718/xdebug.so
sudo nano /etc/php/7.2/apache2/php.ini
scroll to bottom > paste:
[XDebug]
sudo nano /etc/php/7.2/apache2/php.ini
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_host = 192.168.33.0
xdebug.remote_port = 9000
xdebug.remote_log = /var/log/xdebug.log
restart apache: sudo service apache2 restart or if using https you will need
sudo a2enmod ssl;sudo service apache2 restart
in visual studio Code > xDebug config was 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",
"pathMappings": {
"/var/www/public/": "${workspaceRoot}"
},
"port": 9000,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I hope this helps somebody as took me hours to work out :)

Categories