Skip to content

Instantly share code, notes, and snippets.

@ralphschindler
Created February 9, 2024 16:20
Show Gist options
  • Save ralphschindler/460b0e3e93770910a183add51fd269c4 to your computer and use it in GitHub Desktop.
Save ralphschindler/460b0e3e93770910a183add51fd269c4 to your computer and use it in GitHub Desktop.
Enable/Disable Xdebug Via CLI Script
#!/bin/bash
QUIET=0
restart_php_fpm () {
if [ $QUIET -eq 1 ]; then
sv restart php-fpm > /dev/null
else
sv restart php-fpm
fi
}
# handle opts
while getopts ":q" option; do
case $option in
q)
QUIET=1
;;
*)
echo "Bad option ${option} provided)"
exit 1
;;
esac
done
shift $((OPTIND -1))
DIRECTION=$1
# Handle Args
case $DIRECTION in
on)
if [ $QUIET -eq 0 ]; then
echo "enabling xdebug, using always on settings, restarting php-fpm"
fi
cp /etc/php/8.2/mods-available/xdebug/xdebug-debug-on.ini /etc/php/8.2/mods-available/xdebug.ini
phpenmod xdebug
restart_php_fpm
;;
off)
if [ $QUIET -eq 0 ]; then
echo "disabling xdebug, restarting php-fpm"
fi
phpdismod xdebug
restart_php_fpm
;;
trigger)
if [ $QUIET -eq 0 ]; then
echo "enabling xdebug, using trigger settings, restarting php-fpm"
fi
cp /etc/php/8.2/mods-available/xdebug/xdebug-debug-trigger.ini /etc/php/8.2/mods-available/xdebug.ini
phpenmod xdebug
restart_php_fpm
;;
*)
echo "must be one of on, off, or trigger"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment