Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable/Disable xDebug depending on env.
#!/usr/bin/env bash
###
# A CMD or ENTRYPOINT script for a Dockerfile to use to start a Nginx/PHP-FPM
#
# For more details, see 🐳 https://shippingdocker.com
##
if [ ! "production" == "$APP_ENV" ] && [ ! "prod" == "$APP_ENV" ]; then
# Enable xdebug
## FPM
ln -sf /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini
## CLI
ln -sf /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini
else
# Disable xdebug
## FPM
if [ -e /etc/php/7.0/fpm/conf.d/20-xdebug.ini ]; then
rm -f /etc/php/7.0/fpm/conf.d/20-xdebug.ini
fi
## CLI
if [ -e /etc/php/7.0/cli/conf.d/20-xdebug.ini ]; then
rm -f /etc/php/7.0/cli/conf.d/20-xdebug.ini
fi
fi
# Config /etc/php/7.0/mods-available/xdebug.ini
# to correctly set the remote_host to your host computer's IP address
sed -i "s/xdebug\.remote_host\=.*/xdebug\.remote_host\=$XDEBUG_HOST/g" /etc/php/7.0/mods-available/xdebug.ini
# start supervisord, which
# in turn will start Nginx/PHP-FPM
/usr/bin/supervisord
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=docker
; This IP address will get changed
; dynamically when the container starts
xdebug.remote_host=192.168.1.2
@fideloper

This comment has been minimized.

Copy link
Owner Author

commented Dec 24, 2016

Requires the following environment variables:

  • APP_ENV - e.g. "local", "production", "dev"
  • XDEBUG_HOST - an IP of your host machine, accessible by a container. On a Mac, obtain this like so:
export XDEBUG_HOST=$(ipconfig getifaddr en1)
@cnaslain

This comment has been minimized.

Copy link

commented Sep 20, 2018

You need to run your container as root to be allowed to create these sym links... am I correct?
If so, this doesn't match Docker' security best-practices. Is there an alternative solution using maybe confd to set this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.