Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BartJan's avatar

How To: Debug your laravel in VSCode!

Hi guys!

As yesterday i'd spend some time setin'up PHP debugging for Visual Studio Code, as all works fine by now, lets explain how to set this up!

As VSCode is still under development and many great add'ons are allready available, I think this is really a promissing compaditor for the text editors around, like Sublime and Atom.

*I'm under the OSX Env!

  1. You should download Visual Studio Code https://code.visualstudio.com/Download
  2. As Php7 is out now, we should upgrade to the latest version! Note* that this took me like an hour, to upgrade there are like a dozen of tutotials out there that are just all different!
    Get on with Homebrew and just follow this link: https://mhdzaherghaibeh.name/2015/12/26/how-tow-installing-php-7-on-mac/

At this stage it might be that your Homebrew breaks, Dont panic, just de-install Homebrew by using this script: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/FAQ.md#how-do-i-uninstall-homebrew and re-install with: http://brew.sh/

All set and done right? reboot your server and do a quick check if the php is really updated to 7 by simply: "php -v" in your teminal.

  1. Lets get on and install, xDebug, the php extention that handles the debugging for php files :) As we have Homebrew installed, just brew it up by: brew install php70-xdebug , in your terminal.

  2. Lets Config! Xdebug needs a bit of configuration, and lets refer to the documentation: https://xdebug.org/docs/install

We just setup a clean install for Php7, so your php.ini config file should be there somewere... code /usr/local/etc/php/7.0 -> open your ini file in VSCode add following rules: zend_extension = /path/to/your/xdebug.so -> find this by yourself xdebug.remote_enable = 1 xdebug.remote_connect_back=1 xdebug.remote_port = 8000 xdebug.scream=0 xdebug.show_local_vars=1

  1. Add plugin for Visual Studio to have PHP debugging compatibillity https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug Follow the docs and reboot VSC, you should be ready!

Get to your laravel application,-> go to debug -> set listen for debug (selectbox) and set your port to 8000 in the config.

Done! set breakpoint in your custom code. Run php artisan serve in your terminal -> lauches php server for localhost:8000. For xDebug to start append ONCE this query parameter "?XDEBUG_SESSION_START=15117" or some random number/string as value.

Have Fun!

0 likes
8 replies
JeremyARussell's avatar

How about hooking VS Code up to the Homestead Vagrant environment?

2 likes
wsamoht's avatar

This might be helpful as well - https://tighten.co/blog/debugging-configure-xdebug-and-laravel-homestead-and-vs-code-and-phpunit though it appears xdebug has not been released for PHP 7.2 so debugging in the latest Homestead version doesn't seem possible.

I am able to set the site's PHP version to use 7.1 which works for browser debugging. I haven't been able to get debugging to work with cli and phpunit. Anyone know how to set the PHP version on the cli?

impbob36's avatar

Anyone have a tutorial for debugging Javascript?

wsamoht's avatar

For client side wouldn't you just use Chrome/other browser's debugger in developer tools? If you are trying to debug Node.js, you can take a look here.

impbob36's avatar

@wsamoht Thanks for the link. I have Chrome debugging working.

I'm looking for a laravel-mix watch / mocha-webpack workflow.

When working on javascript, breakpoints don't seem to work because Chrome recieves a webpack-compiled version of javascript. I could edit the public files, but then I'm not the transpiling from laravel-mix.

1 like
iamafasha's avatar

I used these configarations

{
     "version": "0.2.0",
     "configurations": [
         {
             "name": "Listen for XDebug",
             "type": "php",
             "request": "launch",
             "port": 8000
         }

     ]
}

Am I supposed to put the port on which my Laravel app is running? Cause this is not working

Please or to participate in this conversation.