Debugging is one of the most important thing of our application development. To make quality software, debugging is a vital part of development.In this post, i am going to show how to debug PHP with visual studio code.
Visual studio code, developed by microsoft is an open source code editor features integrated debugging for almost all programming language.
To get started first visit https://code.visualstudio.com to download visual studio code. Once VS code installed open it and then you need to install PHP debug extension.
To install PHP Extension just move to the extension in sidebar icons of VS code or you can press CTRL+SHIFT+X to explore extension. After that type PHP debug in search extension and install it.
After successfully installed Extension you need to setup user setting. Just Go to setting or press CTRL+, you will be move to the setting and change executable path as i am showing below.
To configure xdebug in local server you need to go https://xdebug.org/wizard.php and paste here your phpinfo(). After that you will get instructions what to do next.To get phpinfo, go to the browser and type localhost you will be move to the dasboard and here you can find the phpinfo menu just click it and copy all the content by pressing CTRL+A.
Next we need to setup debugging mode in vs code. Just open folder containing PHP Code file and choose the debug mode from the left hand side.
To debug, need to add breakpoint in code. To add breakpoint click on the left of the line where you want to add breakpoint as i am showing showing below.
Breakpoint are indicated by red dot. When execution start on browser, it will stop at breakpoint where we can check the state of the code and variables.
To start debugging just click on the start debugging option. For the first time it will create configuration file, no need to change for our puposes .If everything is setup correctly then VS code will be in debbuging mode. Run your page and you will get your debugging environment in VS code with Xdebug.
Thank you for reading this post. we hope you like this Post, Please feel free to comment below, your suggestion. If you face any issue with this code let us know. We’d love to help!
Tags: application debugging, Debugging, php debugging, PHP extension, Visual code extension, visual studio code, Xdebug