Install the PHP Xdebug extension
The Xdebug extension provides debugging and profiling capabilities for PHP scripts.
The Xdebug extension supports PHP 5.6 through PHP 8.4. The Xdebug extension is not yet supported in PHP 8.5. 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:
- Install build dependencies (packages that are required to build the extension).
- Build the extension’s library file.
- Enable the extension in the PHP configuration.
Install build dependencies
Set environment variables for the package manager.
export DEBIAN_FRONTEND=noninteractiveInstall a compiler and other packages that are required for building PHP extensions.
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-configBuild the extension
The PECL install command compiles the extension’s .so library file.
yes '' | sudo pecl8.4-sp install xdebug-3.4.2yes '' | sudo pecl8.3-sp install xdebug-3.4.2yes '' | sudo pecl8.2-sp install xdebug-3.4.2yes '' | sudo pecl8.1-sp install xdebug-3.4.2yes '' | sudo pecl8.0-sp install xdebug-3.4.2yes '' | sudo pecl7.4-sp install xdebug-3.1.5yes '' | sudo pecl7.3-sp install xdebug-3.1.5yes '' | sudo pecl7.2-sp install xdebug-3.1.5yes '' | sudo pecl7.1-sp install xdebug-2.9.8yes '' | sudo pecl7.0-sp install xdebug-2.7.2yes '' | sudo pecl5.6-sp install xdebug-2.5.5Enable the extension
Configure PHP to load the extension.
sudo bash -c "echo zend_extension=xdebug.so > /etc/php8.4-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php8.3-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php8.2-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php8.1-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php8.0-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php7.4-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php7.3-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php7.2-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php7.1-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php7.0-sp/conf.d/xdebug.ini"sudo bash -c "echo zend_extension=xdebug.so > /etc/php5.6-sp/conf.d/xdebug.ini"Restart PHP-FPM.
sudo service php8.4-fpm-sp restartsudo service php8.3-fpm-sp restartsudo service php8.2-fpm-sp restartsudo service php8.1-fpm-sp restartsudo service php8.0-fpm-sp restartsudo service php7.4-fpm-sp restartsudo service php7.3-fpm-sp restartsudo service php7.2-fpm-sp restartsudo service php7.1-fpm-sp restartsudo service php7.0-fpm-sp restartsudo service php5.6-fpm-sp restartVerify the extension is enabled in PHP.
php8.4-sp -i | grep xdebugphp8.3-sp -i | grep xdebugphp8.2-sp -i | grep xdebugphp8.1-sp -i | grep xdebugphp8.0-sp -i | grep xdebugphp7.4-sp -i | grep xdebugphp7.3-sp -i | grep xdebugphp7.2-sp -i | grep xdebugphp7.1-sp -i | grep xdebugphp7.0-sp -i | grep xdebugphp5.6-sp -i | grep xdebugIf the extension is enabled, you will see output like the following.
/etc/phpX.Y-sp/conf.d/xdebug.ini,xdebugSupport 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 => yesxdebug.auto_trace => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)xdebug.cli_color => 0 => 0xdebug.client_discovery_header => HTTP_X_FORWARDED_FOR,REMOTE_ADDR => HTTP_X_FORWARDED_FOR,REMOTE_ADDRxdebug.client_host => localhost => localhostxdebug.client_port => 9003 => 9003xdebug.cloud_id => no value => no value...Uninstall the Xdebug extension
Uninstalling the extension involves the following steps:
- Disable the extension in the PHP configuration.
- Remove the extension’s library file.
Disable the extension
Remove the extension’s configuration from PHP.
sudo rm /etc/php8.4-sp/conf.d/xdebug.inisudo rm /etc/php8.3-sp/conf.d/xdebug.inisudo rm /etc/php8.2-sp/conf.d/xdebug.inisudo rm /etc/php8.1-sp/conf.d/xdebug.inisudo rm /etc/php8.0-sp/conf.d/xdebug.inisudo rm /etc/php7.4-sp/conf.d/xdebug.inisudo rm /etc/php7.3-sp/conf.d/xdebug.inisudo rm /etc/php7.2-sp/conf.d/xdebug.inisudo rm /etc/php7.1-sp/conf.d/xdebug.inisudo rm /etc/php7.0-sp/conf.d/xdebug.inisudo rm /etc/php5.6-sp/conf.d/xdebug.iniRestart PHP-FPM.
sudo service php8.4-fpm-sp restartsudo service php8.3-fpm-sp restartsudo service php8.2-fpm-sp restartsudo service php8.1-fpm-sp restartsudo service php8.0-fpm-sp restartsudo service php7.4-fpm-sp restartsudo service php7.3-fpm-sp restartsudo service php7.2-fpm-sp restartsudo service php7.1-fpm-sp restartsudo service php7.0-fpm-sp restartsudo service php5.6-fpm-sp restartRemove the extension
The PECL uninstall command removes the extension’s .so library file.
sudo pecl8.4-sp uninstall xdebugsudo pecl8.3-sp uninstall xdebugsudo pecl8.2-sp uninstall xdebugsudo pecl8.1-sp uninstall xdebugsudo pecl8.0-sp uninstall xdebugsudo pecl7.4-sp uninstall xdebugsudo pecl7.3-sp uninstall xdebugsudo pecl7.2-sp uninstall xdebugsudo pecl7.1-sp uninstall xdebugsudo pecl7.0-sp uninstall xdebugsudo pecl5.6-sp uninstall xdebug