If you have not installed the latest version of PHP do refer to this post on How to install PHP 8 on macOS Big Sur using Homebrew. Otherwise, if you have different PHP versions for your different projects, do refer to this post on How to easily switch between PHP versions on macOS?
Check if Xdebug is present
To check if Xdebug is present you can check it through the PHP version.
php -v
Installing Xdebug Extension
To install the extension we'll be using the PECL command and the command is as follow.
pecl install xdebug php -v