Magento 2 on valet(plus) with Xdebug

I am a little ashamed to say that until this day I haven't set up XDebug until today. Some excuses I had was..

  1. I tried but it didn't work... I don't want to spend so much time
  2. I have other priorities...
  3. I can do similar things with logging
  4. Or.. is it even possible???

But today I had it enough. It couldn't take it no more. I was working from home, and I did not have enough task for today. I had to do this. so I found two references that would be super useful... and it was

  • https://magenest.com/en/debug-magento-2-code-xdebug-phpstorm-1/
  • https://medium.com/@hhsadiq/installing-xdebug-with-laravel-valet-on-mac-and-linking-with-phpstorm-9a1c562d1b7d

image tooltip here

Note that remote_port is 9001 instead of 9000, and remote_host is 172.30.1.16 instead of 127.0.0.1 which I got from open networrk preferences. Not so sure the remote_host matters that much. After setting two things in Preferences. Reference : https://dmytropoperechnyy.com/how-to-debug-with-phpstorm-valet-and-xdebug/

  • Preferences -> Languages & Frameworks -> PHP -> CLi interpreter should be ~/.composer/vendor/weprovide/valet-plus(this actually not done by my system but works)
  • Preferences -> Languages & Frameworks -> PHP -> Debug -> Port should be 9000 (Can accept external connections)
  • Preferences -> Languages & Frameworks -> PHP -> Debug -> DBGp Proxy ->should also be 9000

image tooltip here image tooltip here

For ordinary php files, this is pretty enough. But for magento, we have to setup the server.. (maybe it's because it's so big)

  • Preferences -> Languages & Frameworks -> PHP -> Server -> Set Server (but not mapping)
  • add Configuration in Debugger, start debugger

In my case, there was some odd errorly things as php-cs-fixer is having errors a lot, and I have disabled it. Maybe I will update more about this in the future. And also not sure why 9001 does not work also. Will have to dig in more.