Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash script to quickly enable / disable xdebug in a PHP docker container
#!/usr/bin/env bash
# see
if [ "$#" -ne 1 ]; then
SCRIPT_PATH=`basename "$0"`
echo "Usage: $SCRIPT_PATH enable|disable"
exit 1;
# Expects service to be called app in docker-compose.yml
SERVICE_ID=$(docker-compose ps -q app)
if [ "$1" == "enable" ]; then
docker exec -i $SERVICE_ID bash -c \
'[ -f /usr/local/etc/php/disabled/docker-php-ext-xdebug.ini ] && cd /usr/local/etc/php/ && mv disabled/docker-php-ext-xdebug.ini conf.d/ || echo "Xdebug already enabled"'
docker exec -i $SERVICE_ID bash -c \
'[ -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini ] && cd /usr/local/etc/php/ && mkdir -p disabled/ && mv conf.d/docker-php-ext-xdebug.ini disabled/ || echo "Xdebug already disabled"'
docker restart $SERVICE_ID
docker exec -i $SERVICE_ID bash -c '$(php -m | grep -q Xdebug) && echo "Status: Xdebug ENABLED" || echo "Status: Xdebug DISABLED"'

This comment has been minimized.

Copy link

@rvanbaalen rvanbaalen commented May 5, 2021

You're a life saver! Went from 15+ minutes to run 300 tests to 2 minutes by disabling xdebug in my docker container using this script.


This comment has been minimized.

Copy link
Owner Author

@carstenwindler carstenwindler commented May 5, 2021

I'm happy to hear that it helped you @rvanbaalen!

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