Xdebug is an extension for PHP to assist with debugging and development. Xdebug makes development easier by allowing the developer to debug his code in a simple and quick way.
Let’s get started.
The first step before installing Xdebug is to get the
phpinfo(). Start your Apache Server and check the phpinfo. We will use installation wizard to select the correct
.dll file. Copy all the information from top to bottom of output generated by phpinfo() funciton.
After you copying all the text, go to Installation Wizard link and paste on the input box. Submit the form. It will analyze the our output and provide appropriate instruction.
Alternate to the above method, you can simply run the command shown below and copy all the output. Paste the output to the installation wizard link.
After analyzing our output, it will provide us a
.dll file to download. Download the file.
Move .dll file to PHP directory
After you download the .dll file, move this file to the php installation directory inside ext directory. If you are using Xampp, you to the Xampp installation directory. I have installed Xampp on my
G drive. Thus, I will paste the downloaded .dll file to the directory:
Edit php.ini file
Now, we need to edit our
php.ini file. Open this file which is located at the directory
G:\xampp\php. You need to add the following code. You can edit according to your directories.
xdebug.mode=debug xdebug.start_with_request=yes xdebug.client_port=9003 xdebug.client_host = localhost zend_extension="G:\xampp\php\ext\php_xdebug-3.0.3-7.4-vc15-x86_64.dll"
Install Xdebug extension on VSCode
After all the setup above, let’s install an Xdebug extension on our VSCode. In the extension tab, search for “PHP Debug”, and install the extension by Felix Becker.
Final step is to create a
launch.json file in our project. Navigate to the extension tab on the left side. On “Run and Debug” section, choose add config (PHP). This will create a new
launch.json file under
Now, all our setup is ready. We need to create breakpoints on our file and run the debuggin by pressing F5. The code will execute and display different variables, stack on the left side box.