84989

Debugging Laravel application on VSCode

Question:

Has anyone successfully configured VSCode to debug Laravel-based website? After having followed numerous articles and tutorials, I have made it to the point where I can ask VSCode to "Listen to XDEBUG", but I haven't been able to do <em>normal</em> VS-style debugging where I could just hit F5 to launch current the website in my favorite browser and it would break into VSCode when it hit a breakpoint, just like we do in full Visual Studio or Eclipse.

I have following things correctly setup on my machine:

<ul><li>VSCode 1.25.1</li> <li>XAMPP 1.8</li> <li>XDEBUG (configured and working)</li> <li>PHP Debug extension for VSCode</li> </ul>

I'm not sure what launch configuration do I need to use in my launch.json. The two configurations that come with PHP Debug extension look like this:

{ "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9000 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9000 }

While the first configuration works correctly (I can start debugging in that mode in VSCode, then launch my website separately in the browser and it hits the breakpoints), the second configuration fails. It tells me that it cannot locate Controller class (which is a Laravel framework class). Qualifying class name with namespace doesn't do any good either.

My guess is that this has got something to with how the launch configuration is setup. It tries to launch the active script as an independent unit and thus fails to locate the definition of framework classes located in different files. We have to somehow provide launch the website as a single application.

Has anyone done that successfully and tell me what I'm missing here?

Answer1:

Finally got it working. Here are the things if anyone else needs it.

<ol><li>Make sure you have XDEBUG setup and running on your Apache server.</li> <li>Install debugger extension for your favorite browser. Extensions are available for Chrome, Edge and FireFox (can be searched and installed from within VSCode).</li> <li>

Set up you launch.json so that it launches two configs in parallel. This is done through so-called <strong>compound configurations</strong>. Here is mine that launches PHP + XDEBUG and EDGE browser:

{ "version": "0.2.0", "compounds": [ { "name": "Launch & Debug", "configurations": [ "Launch Program", "Launch localhost" ] } ], "configurations": [ { "type": "php", "request": "launch", "name": "Launch Program", "cwd": "${workspaceRoot}", "port": 9000 }, { "name": "Launch localhost", "type": "edge", "request": "launch", "url": "http://localhost/public", "webRoot": "${workspaceRoot}" } ] } </li> <li>Update the above config according to your local settings such as site address, xdebug port etc.</li> <li>Press F5 and your debugging session will start. Browser will launch automatically and you'll be able to hit your breakpoints.</li> </ol>

Recommend

  • Whitescreen in XAMPP and PHPMYADMIN at Chrome
  • PHP & MySQL: mysqli_num_rows() error. What is wrong? [duplicate]
  • how install openssl for php 5.3.5 on windows xp?
  • Getting Error like imap_open(): Couldn't open stream in server
  • Xdebug installed but does not display in Phpinfo for Xampp
  • Recover a table of varchar2 from a pl/sql function in php
  • In magento 2 How to call phtml file in static block
  • Codeigniter+PhpBB function redeclaration
  • Android - FM/Radio Transmitting
  • How to get PHP working in Brackets?
  • Stall when debugging with gdbserver in VSCode - “The preLaunchTask 'docker gdb' cannot be
  • Your credentials did not work Azure VM
  • Strict Standards: Non-static method STemplate::assign() should not be called statically
  • Remote debugging of a Java application launched as a Windows service
  • Laravel : Integrity constraint violation
  • How to return DataSet (xsd) in WCF
  • Spring Cloud Microservice Architecture Confusion
  • Install PHP intl extension on MacOS
  • ADO and msqli connections very slow
  • Play WS (2.2.1): post/put large request
  • Is it possible to access block's scope in method?
  • How can I send an e-mail from a vbs script
  • Different response to non-authenticated users and AJAX calls
  • RectangularRangeIndicator format like triangular using dojo
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Symfony2: How to get request parameter
  • Upload files with Ajax and Jquery
  • Do I've to free mysql result after storing it?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Is there a mandatory requirement to switch app.yaml?
  • A cron job substitute?
  • json Serialization in asp
  • log4net write single file for each call to log.info
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Getting error when using KSoap library to consume .NET web services
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Is it possible to post an object from jquery to bottle.py?
  • Binding checkboxes to object values in AngularJs
  • UserPrincipal.Current returns apppool on IIS