From 95ff0d37584bbf70c7b855639617f6ae4d2cb8a1 Mon Sep 17 00:00:00 2001 From: Michael Contento Date: Wed, 26 Apr 2017 17:16:56 +0200 Subject: [PATCH] Add xdebug support and improve php configuration --- Dockerfile | 20 +++++++++++--- usr/bin/docker-start | 12 +++++++++ .../etc/php/conf.d/00-best-practices.ini | 8 ++++++ usr/local/etc/php/conf.d/00-performance.ini | 26 +++++++++++++++++++ usr/local/etc/php/conf.d/00-security.ini | 20 ++++++++++++++ usr/local/etc/php/conf.d/10-xdebug.ini | 4 +++ 6 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 usr/local/etc/php/conf.d/00-best-practices.ini create mode 100644 usr/local/etc/php/conf.d/00-performance.ini create mode 100644 usr/local/etc/php/conf.d/00-security.ini create mode 100644 usr/local/etc/php/conf.d/10-xdebug.ini diff --git a/Dockerfile b/Dockerfile index d40cad2..919cfa8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,18 @@ -FROM php:7.1-fpm-alpine +FROM php:fpm-alpine MAINTAINER Michael Contento RUN \ # Install dependencies apk add --no-cache nginx supervisor \ -# Install PHP extension +# Install PHP extension: opcache && docker-php-ext-install opcache \ + && rm -f /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini \ +# Install PHP extension: xdebug + && apk add --no-cache g++ make autoconf \ + && pecl install xdebug \ + && apk del g++ make autoconf \ + && rm -rf /tmp/pear \ # Remove (some of the) default nginx config && rm -f /etc/nginx.conf \ && rm -rf /etc/nginx/sites-* \ @@ -22,7 +28,8 @@ RUN \ && rm -rf /var/www \ # ... but ensure it exists with the right owner && mkdir -p /var/www \ - && chown www-data.www-data /var/www + && echo " /var/www/index.php \ + && chown -R www-data.www-data /var/www WORKDIR /var/www @@ -40,6 +47,13 @@ ENV REDIRECT_CODE=302 # "http", "https" or "auto" (which will trust X-Forwarded-Proto) ENV REDIRECT_PROTO="auto" +# Change this to true/1 to enable the xdebug extension for php. You need to change +# some xdebug settings? E.g. xdebug.idekey? Just set a environment variable with the dot +# replaced with an underscore (xdebug.idekey => XDEBUG_IDEKEY) and they xdebug config will +# be changed on container start. This is a fast and simple alternative to adding a custom +# config ini in /usr/local/etc/php/conf.d/ +ENV XDEBUG=false + ADD etc/ /etc/ ADD usr/ /usr/ diff --git a/usr/bin/docker-start b/usr/bin/docker-start index afc8aac..a270543 100755 --- a/usr/bin/docker-start +++ b/usr/bin/docker-start @@ -28,4 +28,16 @@ if [[ -f "/etc/nginx/sites-available/redirect-${REDIRECT_MODE}.conf" ]]; then "/etc/nginx/sites-enabled/redirect-${REDIRECT_MODE}.conf" fi +# Configure or disable XDebug as requested +XDEBUG_INI="/usr/local/etc/php/conf.d/10-xdebug.ini" +if [ ${XDEBUG} = true ] || [ "${XDEBUG}" == "1" ]; then + env \ + | egrep '^XDEBUG_' \ + | sed -e 's/XDEBUG_/xdebug./' \ + | tr 'A-Z' 'a-z' \ + >> "${XDEBUG_INI}" +else + rm -f "${XDEBUG_INI}" +fi + exec /usr/bin/supervisord -c /etc/supervisord.conf diff --git a/usr/local/etc/php/conf.d/00-best-practices.ini b/usr/local/etc/php/conf.d/00-best-practices.ini new file mode 100644 index 0000000..a872af6 --- /dev/null +++ b/usr/local/etc/php/conf.d/00-best-practices.ini @@ -0,0 +1,8 @@ +; Disable deprecated short open tags ("