Dorokhov.codes

Xdebug

Xdebug is a PHP extension that helps with:

  1. Debugging Xdebug allows you to step through your PHP code line by line using an IDE (like PhpStorm or VS Code). This means you can set breakpoints, inspect variables, see the call stack, and find where errors occur — just like in other programming languages.

  2. Profiling It generates detailed performance profiles (in formats like cachegrind) so you can analyze which parts of your code are slow.

  3. Stack Traces & Error Reporting Xdebug provides enhanced stack traces and error messages in the browser or CLI — showing file names, line numbers, function names, and arguments.

  4. Code Coverage Useful for unit testing — it tells you which parts of your code have been executed and which haven’t, helping ensure tests cover all branches.

Installation using PECL

pecl install "xdebug"
pecl install "xdebug-3.1.0"

Check installation

In php-file:

xdebug_info();

On the command line, you can also run php -v. Xdebug and its version number should be present as in:

PHP 7.4.16 (cli) (built: Mar 13 2021 02:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies
    with Xdebug v3.0.3, Copyright (c) 2002-2021, by Derick Rethans

Configuration

For Xdebug 3:

xdebug.mode=debug 
xdebug.start_with_request=yes 
xdebug.client_host=192.168.160.1

You have to replace the IP address with your own.

Useful information

Troubleshooting

Make sure that xdebug extension is loaded:

php -m | grep xdebug

phpStorm config

Make sure you have similar config for your IDE:

phpstorm.png