Skip to content

Instantly share code, notes, and snippets.

@webcultist
Forked from rhukster/xdebug
Created February 25, 2020 02:06
Show Gist options
  • Save webcultist/2c8a4ff637b820e21121fd5912223416 to your computer and use it in GitHub Desktop.
Save webcultist/2c8a4ff637b820e21121fd5912223416 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# http://github.com/w00fz/xdebug-osx
#
# @author Djamil Legato http://github.com/w00fz/xdebug-osx
# @modified Andy Miller - Homebrew/core compatibility
# @license MIT
# @version 1.2
app="$(basename "$0")"
command="$1"
options="$2"
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
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"
IS_PHP_FPM=false
SERVER_NAME="apache"
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 [ $# -ge 1 ] && [ "$command" == "on" ] || [ "$command" == "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
if [ -f ~/Library/LaunchAgents/homebrew.mxcl.php"${php_version}".plist ]; then
IS_PHP_FPM=true
SERVER_NAME="php-fpm"
fi
if [ "$options" == '--no-server-restart' ]; then
echo ""
echo "Xdebug has been $STATUS. Will not restart $SERVER_NAME"
else
if [ "$IS_PHP_FPM" == true ]; then
echo ""
echo "Xdebug has been $STATUS, restarting $SERVER_NAME"
brew services restart php"${php_version}"
else
echo ""
echo "Xdebug has been $STATUS, restarting $SERVER_NAME (it might ask for your password)"
sudo pkill -9 httpd
sudo apachectl -k restart > /dev/null 2>&1
fi
fi
else
echo ""
echo "Usage: ${app} <on | off> [--no-server-restart]"
fi
echo ""
echo "You are running PHP v$php_version_dot with Xdebug $STATUS"
echo ""
php -v
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment