Open the terminal and type this command:
php -v
If you are using a local PHP
version from homebrew
or
use Valet
to set multiple PHP
versions, with this command you would get the current version
Depending on your Mac architecture it could change (intel
/m1
)
pecl install xdebug
arch -arm64 sudo pecl install xdebug
Or this other command, depending on how PHP
is compiled, and the MacOS
architecture
arch -x86_64 sudo pecl install xdebug
In the terminal run
php --ini
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
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
If you prefer to make the change in the terminal, you can use nano editor
nano /opt/homebrew/etc/php/8.0/php.ini
Then at the very end add to the file this lines
zend_extension=xdebug
xdebug.mode=develop,debug,coverage
It would set XDEBUG
and also set and XDEBUG mode
, useful when you are using the --coverage
flags to run your tests.
Now we are ready to test the installation by checking again the PHP
version
php -v
Now it should show something like this
Thanks for reading!
Sign up & get tips and tricks
You'll get monthly updates regarding my most recent articles and products.