2. Introduction to Xdebug
Xdebug is an extension for PHP, and provides a range of features to improve the
PHP development experience.
● Step Debugging
● Improvements to PHP's error reporting
● Tracing
● Profiling
● Code Coverage Analysis
3. Installing Xdebug
System Config => Ubuntu + PHP7.x + VSCode + Chrome
● Install php xdebug extension
○ sudo apt-get install php-xdebug (Latest) OR
○ sudo apt install php7.4-xdebug (Version Specific) OR
○ sudo apt -y install php7.4-dev php-pear (PECL Package)
sudo pecl channel-update pecl.php.net
sudo pecl clear-cache
sudo pecl install xdebug
● Install the php debug by Felix Becker extension from extensions
● Install Xdebug helper extension for chrome
4. Configuring Xdebug
Open xdebug.ini
● Important configuration
○ xdebug.mode = off | debug | profile | trace
○ xdebug.start_with_request = default | yes | no | trigger
○ xdebug.client_port=9003
● VS Code Configuration
○ launch.json
5. Xdebug Terminology
● Breakpoint
○ This is a marker you place in the code.
○ When the PHP parser arrives at this line, the execution “breaks” and you can begin
inspecting variables.
● Step Over
● Step Into
● Step Out
● Pause / Resume
● Restart
● Stop
6. Xdebug Usage
● Debug Console
○ Evaluate expressions
● Variables
○ See the variable available in the given scope
● Watches
○ Watch over variables or expressions.
○ These are constantly executed so you can easily see their current value
● Call Stack
○ Shows all methods that have executed to get us to the breakpoint.
● Conditional Breakpoints
7. Xdebug - CLI and APIs
● Debug from CLI
○ export XDEBUG_CONFIG="idekey=VSCode"
● Debug APIs from Postman
○ Append to API url => ?XDEBUG_SESSION_START=VSCODE
● Debug from Swagger
○ ??
9. Xdebug Profiler
● The profiler analyzes how long every method takes to run, how many times it
runs and how much memory it uses.
● Useful in identifying performance problems.