Skip to content

Instantly share code, notes, and snippets.

@webflo
Created February 10, 2017 13:57
Show Gist options
  • Save webflo/7e18ddc66f61fb2ad3bb455a7d745cc6 to your computer and use it in GitHub Desktop.
Save webflo/7e18ddc66f61fb2ad3bb455a7d745cc6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# http://github.com/w00fz/xdebug-osx
command="$1"
php_version_dot=$(php -r "\$v=explode('.', phpversion() ); echo implode('.', array_splice(\$v, 0, -1));")
php_version="${php_version_dot//./}"
xdebug_conf_path="$(brew --prefix)/etc/php/$php_version_dot/conf.d"
xdebug_conf_file="ext-xdebug.ini"
xdebug_conf=$xdebug_conf_path/$xdebug_conf_file
brew list php$php_version-xdebug 2> /dev/null > /dev/null
if [ $? -eq 0 ]; then
if [ ! -f "$xdebug_conf" ] && [ ! -f "$xdebug_conf.disabled" ]; then
echo ""
echo "The ini file for Xdebug was not found at '$xdebug_conf_path'"
echo "Did you install Xdebug via Homebrew?"
echo "For more informations: http://github.com/w00fz/xdebug-osx/blob/master/README.md"
echo ""
exit 1
else
STATUS="enabled"
if [ -f "$xdebug_conf" ] && [ -f "$xdebug_conf.disabled" ]; then
echo ""
echo "Detected both enabled and disabled Xdebug ini files. Deleting the disabled one."
echo ""
rm -rf "$xdebug_conf.disabled"
STATUS="enabled"
elif [ -f "$xdebug_conf.disabled" ]; then
STATUS="disabled"
fi
if [ $# -eq 1 ] && [ "$1" == "on" ] || [ "$1" == "off" ]; then
if [ "$command" == "on" ]; then
mv "$xdebug_conf.disabled" "$xdebug_conf" 2> /dev/null
STATUS="enabled"
elif [ "$command" == "off" ]; then
mv "$xdebug_conf" "$xdebug_conf.disabled" 2> /dev/null
STATUS="disabled"
fi
echo ""
echo "Xdebug has been $STATUS, restarting php-fpm (it might ask for your password)"
sudo lunchy restart dev.php2-fpm.$php_version_dot > /dev/null 2>&1
else
echo ""
echo "Usage: xdebug [ on | off ]"
fi
echo ""
echo "You are running PHP v$php_version_dot with Xdebug $STATUS"
echo ""
fi
else
echo ""
echo "Xdebug for PHP $php_version_dot was never installed or not installed via Brew."
echo "For more informations: http://github.com/w00fz/xdebug-osx/blob/master/README.md"
echo ""
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment