Debug PHP In VSCode With XDebug - Code Wall

https://www.codewall.co.uk/debug-php-in-vscode-with-xdebug

Enable remote debugging in your php.ini:

For Xdebug v3.x.x:

xdebug.mode = debug
xdebug.start_with_request = yes

For Xdebug v2.x.x:

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000

Se instaleaza extensia de Visual Studio Code:

Se instaleaza extensia de chrome:

  1. Goto the following URL https://chrome.google.com/webstore/category/extensions
  2. Search for ‘xDebug Helper’
  3. Install the extension (It has a green ladybug in the logo) – See image below.

Listen for xDebug

Now, let’s go through the ‘Listen for xDebug method which takes the browser into account.

  1. Open a .php file, for this example the index.php file in the root directory.
  2. Add some code and add some breakpoints. Use F9 shortcut key to add breakpoints.
  3. Change the Debug select option to ‘Listen for xDebug’.
  4. Press F5 to start the debugger.
  5. Open Chrome and navigate to your index.php file, in my case its http://localhost/index.php
  6. Click the new XDebug Helper extension and click the Debug option.
  7. You will notice the helper icon will now turn green (See image below)
  8. Finally, refresh the page in the browser, and VSCode will react and start the debugging process.
  9. Go back into VSCode and you will see that it has stopped at the breakpoint.