phplinuxlaravelubuntuxdebug

How to enable XDebug in VSCode with Ubuntu 22.04


I have followed multiple guides, but it seems none of them provide correct solution and most of them are outdated. XDebug is not working.

Environment: Ubuntu 22.04, PHP 8.1, Laravel 10.

I have working laravel installation, that I develop with:

php artisan serve

I've installed XDebug PHP extension:

sudo apt install php-xdebug

Configuration file seems to be at /etc/php/8.1/mods-available/xdebug.ini.

I have installed XDebug VSCode plugin and I have created launch.json with default content in VSCode.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003
    },
  ]
}

What changes I need to make changes to launch.json or xdebug.ini to enable XDebug "step debugging"?

Edit: Xdebug started working after I set xdebug.mode = debug and xdebug.start_with_request = yes in xdebug.ini.

After changes my /etc/php/8.1/mods-available/xdebug.ini content was:

zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes

Solution

  • You need to start the debugger in VS Code - press F5. Then make sure you have Xdebug helper Browser extension installed, activate it and reload your Laravel page.

    If that does not work, add a xdebug_info(); to the top of your index.php or other PHP file you can load via browser and see if there are any errors, or if the Xdebug debugger is activated.

    Alternatively to the Browser extension, you could put xdebug.start_with_request=1 in your xdebug.ini.

    It could also be you are missing xdebug.mode=debug in your xdebug.ini.

    If that does not work post you xdebug.ini and the output of xdebug_info() here for further help.

    There are also other ways how to make it work but these conditions need to be satisfied: