What is Xdebug?

Xdebug is an extension for PHP, and provides a range of features to improve the PHP development experience.


  • Step Debugging - A way to step through your code in your IDE or editor while the script is executing.
  • Improvements to PHP's error reporting - An improved var_dump() function, stack traces for Notices, Warnings, Errors and Exceptions to highlight the code path to the error
  • Tracing - Writes every function call, with arguments and invocation location to disk. Optionally also includes every variable assignment and return value for each function
  • Profiling - Allows you, with the help of visualisation tools, to analyse the performance of your PHP application and find bottlenecks.
  • Code Coverage Analysis - To show which parts of your code base are executed when running unit tests with PHP Unit.

What Xde­bug is isn’t that com­pli­cat­ed. But mak­ing sure we know how it works, at least at a high lev­el, is impor­tant so we under­stand the tool as we use it. It also makes it eas­i­er to under­stand the set­up process if we know how Xde­bug works.

How to install Xdebug on Ubuntu

Step 1: Prerequisites


  • You should have a running Ubuntu 20.04 LTS Machine.
  • You should have sudo or root access to run privileged commands.
  • You should have apt and dpkg utility available in your Machine.

Step 2: Update Your Machine


This will help system download any missing package updates. If any of the packages needs to be upgraded then run apt upgrade command as well.


Copied!

Step 3: Install PHP Xdebug


In the next step, you can install PHP Xdebug package by using apt install php-xdebug command as shown below. This will download the package along with all its dependencies from default Ubuntu Repo.


Ubuntu (18.04 LTS/Bionic, 20.04 LTS/Focal):

Ubuntu (Ondřej Surý's PPA):

Then check if Xdebug is installed by typing php -v

Then open the file with whatever editor is convenient and make sure it includes the following

Add the following code into it:


zend_extension=xdebug.so
xdebug.mode=develope,debug
xdebug.start_with_request=yes

Save and close :wq

How you install Xdebug depends on your system. There are the following possibilities

Using Xdebug on VS Code

Launch Visual Studio Code and, if the Xdebug extension has not yet been installed, then navigate to the extensions panel, search for PHP Debug and then install and enable the plugin.. It should look something like the image above:


Then to debug on Visual Studio Code, click on Run and Debug then, in the top of the panel, choose Listen for Xdebug and click the Play icon. This will bring up the set of controls for stopping, pausing, starting, stepping over, and stepping into code.

Xdebug is now properly installed, configured, and running on your machine.

From here, starting the Xdebug Helper extension and starting Xdebug within Visual Studio Code will give you everything you need to start debugging your code.

Quick tutorial on how to step debug using Xdebug

I am currently working on a shopify website and did not want to use a shopify plugin so I set out to code my own! Leaving a little bit of instructions here for anyone else who would like to use this as well. Happy coding beautiful people!

Step 1

Launch Visual Studio Code and create a new file called index.php and copy and paste the following code below.

index.php

This script counts from one to a hundred

Step 2

In order to step debug the code create a break point on margin line three

Step 3

Select the Run and Debug tab and click Run and Debug



And the following results must display



Advancing the script:

Congrates this is your first step to debugging using Xdebug ;)

I hope this has been a good introduction to how powerful and valuable using a debugger like Xdebug is for your development workflow, as well as a possible alternative if you find it too complex.

Meet Some Of Our Team

We have the best people for your next big project

Barbara Du Randt

HR

Conrad Rheeder

Site Manager

Keania Niate Eric

Full Stack Developer

Kyla Meyer

Admin Officer

Liaan Kruger

Admin Clerk

Llewellyn Du Randt

Senior Backend Developer

Marvin Milanzi

Software Tester

Rowan Zekbot

Zekini Robot

Contact Us

Feel free to ask any questions

Zekini.com


Johannesburg
Gauteng, South Africa

Nelspruit
Mpumalanga, South Africa

Port Elizabeth
Eastern Cape, South Africa

Lagos
Nigeria

support@zekini.com

Privacy Policy

Your request has been successfully sent

Oh! Your have digged our website in search for the new job?

Keep an eye out for any open vacancies!

Careers