DEV Community

Cover image for How to install and configure Xdebug in linux
Antonio Silva
Antonio Silva

Posted on

How to install and configure Xdebug in linux

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

Installation

Installing Xdebug with a package manager is usually the quickest way. Depending on your distribution, run the following command

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

sudo apt-get install php-xdebug
Enter fullscreen mode Exit fullscreen mode

Ubuntu (OndΕ™ej SurΓ½'s PPA):

sudo apt-get install php(version)-xdebug
Enter fullscreen mode Exit fullscreen mode

For other linux distributions here.

Installing with PECL

You can install Xdebug via PECL on Linux with Homebrew.

Prerequisites:

  • GCC and associated libraries.

  • PHP development headers.

Run:

pecl install xdebug
Enter fullscreen mode Exit fullscreen mode

Configuring

First we have to find the xdebug configuration file, on linux it is located in the following path:

cd /etc/php/your_php_version/mods-available
Enter fullscreen mode Exit fullscreen mode

In this directory you will find xdebug.ini, the xdebugconfiguration file and open the file with a code editor.

sudo your_editor xdebug.ini
Enter fullscreen mode Exit fullscreen mode

Enter the following settings:

zend_extension=xdebug.so
xdebug.mode=debug,develop
xdebug.start_with_request=yes
xdebug.client_port=8000
xdebug.client_host=127.0.0.1
xdebug.cli_color=1
xdebug.show_local_vars=1
Enter fullscreen mode Exit fullscreen mode

In xdebug.client_port enter the port you use in your applications.

Let's check that xdebug has been installed and is working. To do this, use the following php code:

phpinfo();
Enter fullscreen mode Exit fullscreen mode

In the php info you should find an xdebug section.

1

Solving a problem

In the image above, it shows that our xdebug has the Development Helpers and Step Debugger modes active, but if in a given project we want to activate or deactivate any mode without touching the main xdebug file.

To make this possible, we'll use the XDEBUG_MODE environment variable, as in the example below:

XDEBUG_MODE=coverage php -S 127.0.0.1:8000
Enter fullscreen mode Exit fullscreen mode

If we check again in the xdebug section we will only have coverage mode enabled

2

Here are the instructions for the other modes and all the possible xdebug configurations.

This concludes our guide to installing and configuring xdebug on linux.

Don't forget to add a reaction if the post has helped.

Top comments (0)