Skip to content

Instantly share code, notes, and snippets.

@maurotdo
Created March 7, 2014 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save maurotdo/9414973 to your computer and use it in GitHub Desktop.
Save maurotdo/9414973 to your computer and use it in GitHub Desktop.
Simple bash script to turn on & off Xdebug extension Based on Ubuntu 13.10 php5-xdebug extension
#!/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")
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 "done"
echo
echo "Remember to restart Apache if you're debugging in browser"
echo
exit 0
@ABM-Dan
Copy link

ABM-Dan commented Jan 14, 2016

Neat script, but a little comma is wrecking my day: Found xdebug.ini at /etc/php.d/xdebug.ini,

INI=$($PHP -i | grep "xdebug.ini"| tr -d ',') did it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment