How to install and configure Xdebug on Ubuntu?

Introduction

Xdebug is a powerfull tool for debugging PHP. It can display formated errors and embed the usefull var_dump function. This page explains how to install and configure Xdebug.

The following has been tested on a Cloud9 server with the following versions:

Check you configuration

Sometime, Xdebug is not configure, and the var_dump function is not displayed properly. Create a PHP file on your server with the following content:

<?php var_dump( array('CodeIgniter', 'php', 'phpMyAdmin', 'lucidar.me') ); ?>

Check if the display is formated. On the following illustration, var_dump is not displayed properly:

var_dump function is not displayed properly

Check if the Xdebug module is installed. The following command displays the list of PHP modules instaled:

php -m

If Xdebug is already installed (Xdebug is in the list of instaled module), skip the next step.

Install Xdebug

Install the following package:

sudo apt-get install php-xdebug

If you need to install xdebug for a given version, use :

sudo apt-get install php7.3-xdebug

Restart Apache2 manualy or with the following command:

sudo service apache2 restart

Configure Xdebug

Check if var_dump is now formated properly. If not, add or update the html_errors parameter in your php.ini file:

html_errors = On

Display should now be formated:

var_dump function is displayed properly

Optional configuration

I also strongly recommand to set the following parameters only on your local environment in your php.ini. This will display PHP errors and warning in the page:

display_errors = On
display_startup_errors = On
error_reporting = E_ALL

See also


Last update : 11/23/2021