8

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?

3
  • Have you tried to put xdebug_break(); into your blade file? Commented May 4, 2018 at 11:21
  • 1
    I place the following test code into my blade file: <?php xdebug_break(); phpinfo(); ?> But then I get Call to undefined function xdebug_break() error? Commented May 4, 2018 at 12:03
  • 2
    Success...finally. The reason for the undefined function xdebug_break() error was I had forgotten to copy my XDebug dll file to my xamp/php/ext folder. Now when I use xdebug_break(); in VS Code the breakpoint is reached. Commented May 4, 2018 at 13:18

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for sharing the steps. I'm lost at "In VS Code, set a breakpoint in the file you want to debug". On my debug panel I see breakpoints section but I couldn't add the line I want to the breakpoints section. How exactly do you do it?
@AnuratChapanond To set a breakpoint in VS Code, click the gutter next to the line to break on.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.