I am using VS Code to debug my Laravel project. I have installed the PHP Debug extension and configured PHP to debug using XDebug. Server is Apache (using Xampp). I am able to access my site using my browser, but the breakpoint I set inside my project using VS Code is never hit? What am I doing wrong here?
If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.
Breakpoints# Breakpoints can be toggled by clicking on the editor margin or using F9 on the current line. Finer breakpoint control (enable/disable/reapply) can be done in the Run and Debug view's BREAKPOINTS section.
Enable or disable debug mode using app. Open the app. php file located in your config/app. php laravel project. Search for debug key and change true to enable debug mode and false for disabling debug mode default it will show false.
I am a completely new to VS Code, Laravel & XDebug. I personally battled to set breakpoints in VS Code so I could debug my Laravel project. I am posting this to try and help any other beginners out there who battled to set breakpoints in VS Code in order to debug a Laravel project.
Visual Studio Code + Xampp + XDebug Debugging:
Install VS Code
Install Xampp
In VS Code: Ctrl + J
Confirm PHP is installed: php -v
Install PHP Debug (Debug support for PHP with XDebug) extension in VS Code by clicking on Install
Use Xampp to get your php.ini information
Install XDebug:
1.1 Use XDebug Installation Wizard (https://xdebug.org/wizard.php) to generate dll needed.
1.2 Download generated dll XDebug file to: C:\xampp\php\ext
1.3 Configure PHP to use XDebug -Go to Xampp and open php.ini file -Add the following:
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = "C:\xampp\php\ext\php_xdebug-2.6.0-7.2-vc15.dll" (change this to your version of dll file)
1.4 Change default Xampp project directory:
-in Xampp Control Panel go to Apache config and select httpd.config
-in httpd.config go to "DocumentRoot" and change from "C:/xampp/htdocs" to a local folder where PHP projects are located.
-in httpd.config go to "DocumentRoot"'s "Directory" and change from "C:/xampp/htdocs" to same local folder where PHP projects are located.
example: DocumentRoot "C:/xampp/htdocs"
Directory "C:/xampp/htdocs"
changed to:
DocumentRoot "C:/Users/..."
Directory "C:/Users/..."
In VS Code goto File --> Preferences --> Settings
Add the following: php.validate.executablePath: "C:\xampp\php\php.exe"
To debug project in VS Code:
-First delete current launch.json file in .vscode
-Click on Debug --> Configure or Fix "launch.json" --> Select PHP (this will create a new launch.json file)
-In your browser, Goto localhost and open your website (project you want to debug)
-In VS Code, set a breakpoint in the file you want to debug (make sure it is in a PHP command section)
-In VS Code click on Debug --> "Listen for XDebug"
-In your browser refresh your website
-In VS Code your breakpoint should hit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With