2

I'm using Laravel Sail for my development environment and I'm wanting to use Xdebug to debug my PHP Laravel code.

I've set up Xdebug as per the documentation here: https://laravel.com/docs/9.x/sail#debugging-with-xdebug

However, the documentation only shows how to Xdebug from a browser or debugging CLI commands, what about APIs? If I set a breakpoint in my PHP code and use Postman to send an API request it does not hit any breakpoints. As a quick test, I opened my browser with the Xdebug extension and typed in the API url, the breakpoint works.

This is NOT the way I want to be debugging my code, I can't debug my APIs properly because they require certain parameters and body contents with certain headers which I can't do in a browser.

So this begs the question, how do you APIs using Xdebug in Laravel Sail?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Courtney White
  • 612
  • 8
  • 22
  • *"If I set a breakpoint in my PHP code and use Postman to send an API request it does not hit any breakpoints. "* Add Xdebug cookie to your request: https://stackoverflow.com/a/19147935/783119 – LazyOne May 25 '22 at 14:17
  • Thanks for asking this @Courtney White, I'm also experiencing the same exact issue and can't find a way to make it work, especially for backend API calls. – Morgy Jun 23 '22 at 08:35

1 Answers1

3

You can do one of two things:

  1. Set the XDEBUG_SESSION=somevalue cookie with your API call.
  2. Change (or add) the xdebug.start_with_request setting to yes (instead of the default, which is trigger). Use xdebug_info() to find out which ini file to change.
Derick
  • 35,169
  • 5
  • 76
  • 99