Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Forked from maurotdo/xdebug.sh
Last active January 14, 2016 17:06
Show Gist options
  • Save ABM-Dan/320907ddc83eb8f98bc9 to your computer and use it in GitHub Desktop.
Save ABM-Dan/320907ddc83eb8f98bc9 to your computer and use it in GitHub Desktop.
Extended version of a bash script to turn xdebug on or off, it automatically restarts php-fpm after.
#!/bin/bash
#
# Script to turn xdebug on and off
# Permission to copy and modify is granted under the MIT license
# Last revised 2014-03-07
# Mauro Maggi <maurotdo (at) gmail (dot) com>
PHP=$(which php)
XDEBUG=$($PHP -i | grep -i xdebug | grep -i enabled)
INI=$($PHP -i | grep "xdebug.ini" | tr -d ',')
echo "Found xdebug.ini at $INI"
if [ -z "$XDEBUG" ]; then
echo "Xdebug is OFF"
else
echo "Xdebug is ON"
fi
if [ "$1" != "on" -a "$1" != "off" ]; then
echo "Usage: xdebug { on | off }"
exit 2
fi
if [ -z "$INI" ]; then
echo "Cannot detect xdebug.ini location";
exit 1;
fi
echo -n "Turning $1 Xdebug ... "
if [ "off" == "$1" ]; then
sed --in-place --follow-symlinks "s/^/;/g" "$INI"
elif [ "on" == "$1" ]; then
sed --in-place --follow-symlinks "s/^;*//g" "$INI"
fi
echo
service php-fpm restart
echo
echo "done"
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment