Toggle Xdebug on macOS from the terminal

October 24, 2019

When you have the Xdebug extension for PHP installed and enabled, most of your PHP code will run notably slower. A little helper tool called 'Xdebug Toggler for OSX' provides an easy way to quickly enable or disable Xdebug from the terminal:

You can find the source code on GitHub and installing it is easy with Homebrew:

brew install xdebug-osx

# outputs the current status
xdebug-toggle 

# enables xdebug
xdebug-toggle on

# disables xdebug
xdebug-toggle off

# toggles xdebug without restarting apache or php-fpm
xdebug-toggle on|off --no-server-restart

By the way, starting from version 1.3.0 (which has not been released yet), Composer will automatically restart PHP without Xdebug to save some time.