'Xdebug in Laravel is not working with VSCode

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


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1