diff --git a/Dockerfile b/Dockerfile index 4b0275b..63aa89c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,7 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \ && addgroup -S nginx \ && adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \ && apk add --no-cache --virtual .build-deps \ + autoconf \ gcc \ libc-dev \ make \ @@ -149,6 +150,8 @@ RUN echo @testing http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repo openssl-dev \ ca-certificates \ dialog \ + autoconf \ + make \ gcc \ musl-dev \ linux-headers \ @@ -168,6 +171,7 @@ RUN echo @testing http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repo --with-jpeg-dir=/usr/include/ && \ #curl iconv session docker-php-ext-install pdo_mysql pdo_sqlite mysqli mcrypt gd exif intl xsl json soap dom zip opcache && \ + pecl install xdebug && \ docker-php-source delete && \ mkdir -p /etc/nginx && \ mkdir -p /var/www/app && \ @@ -181,7 +185,7 @@ RUN echo @testing http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repo pip install -U pip && \ pip install -U certbot && \ mkdir -p /etc/letsencrypt/webrootauth && \ - apk del gcc musl-dev linux-headers libffi-dev augeas-dev python-dev + apk del gcc musl-dev linux-headers libffi-dev augeas-dev python-dev make autoconf # ln -s /usr/bin/php7 /usr/bin/php ADD conf/supervisord.conf /etc/supervisord.conf diff --git a/README.md b/README.md index a086df1..b5cbdc6 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ For more detailed examples and explanations please refer to the documentation. - [Setup](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/lets_encrypt.md#setup) - [Renewal](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/lets_encrypt.md#renewal) - [PHP Modules](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/php_modules.md) +- [Xdebug](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/xdebug.md) - [Logging and Errors](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/logs.md) ## Guides diff --git a/docs/xdebug.md b/docs/xdebug.md new file mode 100644 index 0000000..0b6eecf --- /dev/null +++ b/docs/xdebug.md @@ -0,0 +1,6 @@ +## Install PHP Modules +Xdebug comes pre-installed. To enable xdebug you need to add a couple environment variables: + +- `ENABLE_XDEBUG=1` This will add the xdebug.ini to your php extensions +- `XDEBUG_CONFIG=remote_host=you.local.ip.here` Sets an xdebug remote host environment var. This is usually your actual local computers IP. +- `PHP_IDE_CONFIG=serverName=NameUsedInPhpStormServerConfig` This is an example of how to use this in PhpStorm. You configure a server in php storm with a name, set that in this var. diff --git a/scripts/start.sh b/scripts/start.sh index d0f6811..19f4bc3 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -131,6 +131,38 @@ if [ ! -z "$PHP_UPLOAD_MAX_FILESIZE" ]; then sed -i "s/upload_max_filesize = 100M/upload_max_filesize= ${PHP_UPLOAD_MAX_FILESIZE}M/g" /usr/local/etc/php/conf.d/docker-vars.ini fi +# Enable xdebug +XdebugFile='/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini' +if [[ "$ENABLE_XDEBUG" == "1" ]] ; then + if [ -f $XdebugFile ]; then + echo "Xdebug enabled" + else + echo "Enabling xdebug" + echo "If you get this error, you can safely ignore it: /usr/local/bin/docker-php-ext-enable: line 83: nm: not found" + # see https://github.com/docker-library/php/pull/420 + docker-php-ext-enable xdebug + # see if file exists + if [ -f $XdebugFile ]; then + # See if file contains xdebug text. + if grep -q xdebug.remote_enable "$XdebugFile"; then + echo "Xdebug already enabled... skipping" + else + echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > $XdebugFile # Note, single arrow to overwrite file. + echo "xdebug.remote_enable=1 " >> $XdebugFile + echo "xdebug.remote_log=/tmp/xdebug.log" >> $XdebugFile + echo "xdebug.remote_autostart=false " >> $XdebugFile # I use the xdebug chrome extension instead of using autostart + # NOTE: xdebug.remote_host is not needed here if you set an environment variable in docker-compose like so `- XDEBUG_CONFIG=remote_host=192.168.111.27`. + # you also need to set an env var `- PHP_IDE_CONFIG=serverName=docker` + fi + fi + fi +else + if [ -f $XdebugFile ]; then + echo "Disabling Xdebug" + rm $XdebugFile + fi +fi + if [ ! -z "$PUID" ]; then if [ -z "$PGID" ]; then PGID=${PUID}