Visual Studio Code (vs.code) PHP debugging

I just wasted around 7 hours of my life on this thing… life sucks.
All I wanted was to have a debugger working for me on a local development setup.  I solved this once, for phpStorm and WAMP, but somebody told me how great vs.code is and I wanted to have it working. Since I’m tired from all the running around bugs, here is a short summary:

  1. WAMP sucks, windows 10 uses all the default ports, who uses a Microsoft IDE for PHP??
  2. install XAMPP (yes the interface is ugly but it works)
  3. change Apache port from 80 to another (90)
  4. xDebug comes with XAMPP, but not enabled. Edit php.ini and add the following (at the end):

    notice the port is not 9000 (default), but 9001. Change the folder location to the one on your machine
  5. add PHP location to the systems path: it’s in the system’s environment variables. What I added was: “C:\xampp\php\” (this is the “PATH” variable)
  6. install vs.code and the php-debug extension. Next steps are in vs.code
  7. press F1, type “user settings (JSON)” press enter. Add the following settings:

    again, use the folder location on your machine
  8. Open the debug window (no bugs icon). Choose PHP as the debugger
  9. press the gear icon for settings. Change the port number to the one used in item 4 above (9001)
  10. Should work now. If it doesn’t restart everything (Apache, vs.code, computer). Still not working? You can waste precious hours as I did or just smash the computer on the floor
  11. There are two debug modes:
    Launch debug will do everything inside vs.code – show you the output and all the information around it.
    Listen mode will seem like it does nothing, but it will work when the page is opened in your browser.

One comment

  1. if the debug process seems to work, but doesn’t break on break-points – probably the xdebug port is not the same as in php.ini
    Click on the gear icon in the debug window and check the port.

Leave a Reply

Your email address will not be published. Required fields are marked *