Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

assertcarl's avatar

XDebug MacOS Toggle using Valet with XDebug installed via PECL

I was using xdebug-osx to toggle XDebug on and off but after reinstalling php I was unable to install XDebug through homebrew and forced to install using PECL so this is what I came up with to be able to toggle it on and off.

Hopefully someone else will find this useful.

function xdebug()
{
    if [[  == "on" ]]; then
        tput setaf 2; echo "Enabling XDebug..."
        sed -i -e 's/#zend_extension=\"xdebug.so\"/zend_extension=\"xdebug.so\"/g' /usr/local/etc/php/7.2/php.ini && rm /usr/local/etc/php/7.2/php.ini-e && valet restart
    elif [[  == "off" ]]
    then
        tput setaf 2; echo "Disabling XDebug..."
        sed -i -e 's/zend_extension=\"xdebug.so\"/#zend_extension=\"xdebug.so\"/g' /usr/local/etc/php/7.2/php.ini && rm /usr/local/etc/php/7.2/php.ini-e && valet restart
    fi
}

Edit: seems $1 has been stripped from the if statements, no idea why but you'll want to add them back.

0 likes
0 replies

Please or to participate in this conversation.