DEV Community

Ariel Mejia
Ariel Mejia

Posted on

Install XDEBUG in MontereyOS

Check the PHP current version

Open the terminal and type this command:

php -v
Enter fullscreen mode Exit fullscreen mode

If you are using a local php version from homebrew or use Valet to set multiple php versions, with this command you would get exactly the current version.

Install XDEBUG

Depending on your Mac architecture it could change (intel/m1)

With Homebrew (intel)

pecl install xdebug
Enter fullscreen mode Exit fullscreen mode

On Apple M1

arch -arm64 sudo pecl install xdebug
Enter fullscreen mode Exit fullscreen mode

Or this other command, depending on how PHP is compiled, and what the default architecture is:

arch -x86_64 sudo pecl install xdebug
Enter fullscreen mode Exit fullscreen mode

Get the php.ini file location

In the terminal run this command:

php --ini
Enter fullscreen mode Exit fullscreen mode

You would get four values, the second line returns the php.ini file location, with this you can open a text editor and add xdebug.

Add XDEBUG

In my case I am using php 8.0.18 so the php.ini file location is: /opt/homebrew/etc/php/8.0/php.ini

Now you can open the file with an editor, in my case I am using vscode for this little changes, so in my terminal I use this command:

code /opt/homebrew/etc/php/8.0/php.ini
Enter fullscreen mode Exit fullscreen mode

If you prefer to make the change in the terminal, you can use, this other command:

nano /opt/homebrew/etc/php/8.0/php.ini
Enter fullscreen mode Exit fullscreen mode

Then at the very end add to the file this lines:

zend_extension=xdebug
xdebug.mode=develop,debug,coverage
Enter fullscreen mode Exit fullscreen mode

It would set XDEBUG and also set and XDEBUG mode, useful when you are using the --coverage flags to run your tests.

Test your XDEBUG configuration

Now we are ready to test the installation by running this command:

php -v
Enter fullscreen mode Exit fullscreen mode

Now it should show something like this:

Image description

Top comments (0)