diff --git a/Dockerfile b/Dockerfile index 5bcacc2..f4e71c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,12 @@ RUN chmod 777 /tmp && chmod +t /tmp RUN /tmp/setup/php-extensions.sh RUN /tmp/setup/oci8-extension.sh +RUN chmod +x /usr/bin/moodle-php-entrypoint +ENTRYPOINT ["moodle-php-entrypoint"] + RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \ mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \ mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \ mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps + +CMD ["apache2-foreground"] \ No newline at end of file diff --git a/README.md b/README.md index 9e5c142..57b9bb6 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ To faciliate testing and easy setup the following directories are created and ow * `/var/www/behatdata` * `/var/www/behatfaildumps` +# Xdebug + +For development, the image contains the Xdebug PHP extension. This is disabled by default, for performance reasons, but can be enabled by setting a non-empty XDEBUG_CONFIG environment variable. This environment variable is also used by Xdebug for configuration (see [XDebug documentation](https://xdebug.org/docs) for details and available configuration settings). + +```bash +$ docker run --name web0 -p 8080:80 -v $PWD:/var/www/html -e XDEBUG_CONFIG="remote_enable=1 remote_connect_back=1" moodlehq/moodle-php-apache:7.1 +``` # See also This container is part of a set of containers for Moodle development, see also: diff --git a/root/tmp/setup/php-extensions.sh b/root/tmp/setup/php-extensions.sh index e479f9a..18dbe25 100755 --- a/root/tmp/setup/php-extensions.sh +++ b/root/tmp/setup/php-extensions.sh @@ -48,6 +48,8 @@ ACCEPT_EULA=Y apt-get install -y msodbcsql pecl install sqlsrv-4.3.0 docker-php-ext-enable sqlsrv +pecl install xdebug-2.6.1 + # Keep our image size down.. pecl clear-cache apt-get remove --purge -y $BUILD_PACKAGES diff --git a/root/usr/bin/moodle-php-entrypoint b/root/usr/bin/moodle-php-entrypoint new file mode 100644 index 0000000..dcdcc8b --- /dev/null +++ b/root/usr/bin/moodle-php-entrypoint @@ -0,0 +1,30 @@ +#!/bin/sh + +XDEBUG_INI_FILE=/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +if [ -z "${XDEBUG_CONFIG}" ]; then + rm -f $XDEBUG_INI_FILE +else + if [ ! -e $XDEBUG_INI_FILE ]; then + # Enable the extension. + echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > $XDEBUG_INI_FILE + # Configure the main settings, keeping features disabled. + cat <> $XDEBUG_INI_FILE +# Code coverage. +xdebug.coverage_enable = 0 +# Stack trace. +xdebug.default_enable = 0 +# Remote debug. +xdebug.remote_enable = 0 +xdebug.remote_host = localhost +xdebug.remote_port = 9000 +xdebug.remote_autostart = 1 +# Profiling: https://docs.moodle.org/dev/Profiling_PHP#Quick_summary +xdebug.profiler_enable = 0 +xdebug.profiler_enable_trigger = 0 +xdebug.profiler_output_dir = /tmp +xdebug.profiler_output_name = cachegrind.out.%R.%u +EOF + fi +fi + +/usr/local/bin/docker-php-entrypoint "$@"