Skip to content

Instantly share code, notes, and snippets.

@renekreijveld
Last active July 19, 2024 08:20
Show Gist options
  • Save renekreijveld/3f4ee78009ce0d0e52751d8f80dcd048 to your computer and use it in GitHub Desktop.
Save renekreijveld/3f4ee78009ce0d0e52751d8f80dcd048 to your computer and use it in GitHub Desktop.
XDebug script to switch xdebug on or off
#!/bin/bash
#
# Xdebug switcher for Homebrew based NginX, MariaDB, PHP development stack
# Written by: René Kreijveld, 18/07/2027
# Based on the work of Djamil Legato and Andy Miller
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"
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
restartphpfpm
else
echo ""
echo "Usage: ${app} <on | off>"
fi
php -v
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment