Configure Xdebug modes

Xdebug modes control which debugging features are available and are configured in your PHP configuration file.

Xdebug has different operating modes which control what features are available. These modes are set in your PHP configuration file, php.ini.

You can locate your php.ini file by running:

php -i | grep php.ini

Look for the line which shows the php.ini file location, which for me is:

/opt/homebrew/etc/php/8.3/php.ini

Open the file, and look for the xdebug.mode property. This property may not yet exist, in which case you can add it to the file.

You can make Xdebug available for debugging by setting this value to “debug”:

xdebug.mode=debug

And you could also set multiple modes by separating them with commas, like so:

xdebug.mode=debug,trace,profile

Note that there are a few modes which you can enable, including:

  • debug: Enables step debugging
  • trace: Enables function traces
  • profile: Enables profiling
  • develop: Enables development aids
  • gcstats: Enables garbage collection statistics
  • coverage: Enables code coverage analysis

The most common mode is debug, which enables step debugging. Without this mode enabled, step debugging features won't work.

You can check your current Xdebug mode by again using grep, and searching for “xdebug.mode”:

php -i | grep xdebug.mode

When you see the output, you'll notice two values displayed. The first is called the "local" value - this is what's currently active and in use. The second is the "master" value, which comes from your php.ini file. Sometimes these values might be different if something else is overriding your php.ini settings.

These overrides can come from a few places - maybe an .htaccess file, a .user.ini file, or even from your code itself using ini_set(). For most users working locally, these values will usually match, but it's good to know why they might be different.

You could also get the PHP settings by creating a PHP file with:

phpinfo.php
<?php
phpinfo();

…and then look for the "xdebug.mode" setting in the output.

Remember that any changes to the php.ini file also require the web server to be restarted, so to be sure to restart your web server, otherwise the changes will not take effect.

M Bytes Newsletter

Get the developer newsletter

Fresh bytes every Thursday. No spam, ever. Unsubscribe anytime.

Join 9,000+ developers and get three free video lessons every week.