How to install PHP Xdebug

I needed to setup XDebug for a tool with Pest so I decided to go through the steps to install on my machine.

Of course PHP will be required to be installed first before adding XDebug

Open the terminal and run the following.

sudo pecl install xdebug

Open up the php.ini file to edit it.

nano /etc/php/8.3/cli/php.ini

Add the following line to the file to load the Xdebug extension.

zend_extension=/usr/lib/php/20230831/xdebug.so

To verify that Xdebug is setup correctly use the PHP version command.

php -v

You will see the Xdebug text in the PHP version output.

PHP 8.3.6 (cli) (built: Apr 11 2024 20:23:58) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies