Skip to content

Install the PHP Xdebug extension

The Xdebug extension provides debugging and profiling capabilities for PHP scripts.

The Xdebug extension supports PHP 5.6+. See the Xdebug supported versions chart and the list of Xdebug releases for the specific extension versions that are supported for each PHP version.

Install the Xdebug extension

Installing the extension involves the following steps:

  1. Install build dependencies (packages that are required to build the extension).
  2. Build the extension’s library file.
  3. Enable the extension in the PHP configuration.

Install build dependencies

Set environment variables for the package manager.

Terminal window
export DEBIAN_FRONTEND=noninteractive

Install a compiler and other packages that are required for building PHP extensions.

Terminal window
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config

Build the extension

The PECL install command compiles the extension’s .so library file.

Terminal window
yes '' | sudo pecl8.4-sp install xdebug-3.4.2

Enable the extension

Configure PHP to load the extension.

Terminal window
sudo bash -c "echo zend_extension=xdebug.so > /etc/php8.4-sp/conf.d/xdebug.ini"

Restart PHP-FPM.

Terminal window
sudo service php8.4-fpm-sp restart

Verify the extension is enabled in PHP.

Terminal window
php8.4-sp -i | grep xdebug

If the extension is enabled, you will see output like the following.

/etc/phpX.Y-sp/conf.d/xdebug.ini,
xdebug
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
Enabled Features (through 'xdebug.mode' setting)
'xdebug://gateway' pseudo-host support => yes
'xdebug://nameserver' pseudo-host support => yes
xdebug.auto_trace => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.cli_color => 0 => 0
xdebug.client_discovery_header => HTTP_X_FORWARDED_FOR,REMOTE_ADDR => HTTP_X_FORWARDED_FOR,REMOTE_ADDR
xdebug.client_host => localhost => localhost
xdebug.client_port => 9003 => 9003
xdebug.cloud_id => no value => no value
...

Uninstall the Xdebug extension

Uninstalling the extension involves the following steps:

  1. Disable the extension in the PHP configuration.
  2. Remove the extension’s library file.

Disable the extension

Remove the extension’s configuration from PHP.

Terminal window
sudo rm /etc/php8.4-sp/conf.d/xdebug.ini

Restart PHP-FPM.

Terminal window
sudo service php8.4-fpm-sp restart

Remove the extension

The PECL uninstall command removes the extension’s .so library file.

Terminal window
sudo pecl8.4-sp uninstall xdebug