|
| 1 | +FROM php:7.4-apache |
| 2 | + |
| 3 | +# persistent dependencies |
| 4 | +RUN set -eux; \ |
| 5 | + apt-get update; \ |
| 6 | + apt-get install -y --no-install-recommends \ |
| 7 | +# Ghostscript is required for rendering PDF previews |
| 8 | + ghostscript \ |
| 9 | + ; \ |
| 10 | + rm -rf /var/lib/apt/lists/* |
| 11 | + |
| 12 | +# install the PHP extensions we need (https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions) |
| 13 | +RUN set -ex; \ |
| 14 | + \ |
| 15 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 16 | + \ |
| 17 | + apt-get update; \ |
| 18 | + apt-get install -y --no-install-recommends \ |
| 19 | + libfreetype6-dev \ |
| 20 | + libjpeg-dev \ |
| 21 | + libmagickwand-dev \ |
| 22 | + libpng-dev \ |
| 23 | + libzip-dev \ |
| 24 | + ; \ |
| 25 | + \ |
| 26 | + docker-php-ext-configure gd \ |
| 27 | + --with-freetype-dir=/usr \ |
| 28 | + --with-jpeg-dir=/usr \ |
| 29 | + --with-png-dir=/usr \ |
| 30 | + ; \ |
| 31 | + docker-php-ext-install -j "$(nproc)" \ |
| 32 | + bcmath \ |
| 33 | + exif \ |
| 34 | + gd \ |
| 35 | + mysqli \ |
| 36 | + opcache \ |
| 37 | + zip \ |
| 38 | + ; \ |
| 39 | + pecl install imagick-3.4.4; \ |
| 40 | + docker-php-ext-enable imagick; \ |
| 41 | + \ |
| 42 | +# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies |
| 43 | + apt-mark auto '.*' > /dev/null; \ |
| 44 | + apt-mark manual $savedAptMark; \ |
| 45 | + ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \ |
| 46 | + | awk '/=>/ { print $3 }' \ |
| 47 | + | sort -u \ |
| 48 | + | xargs -r dpkg-query -S \ |
| 49 | + | cut -d: -f1 \ |
| 50 | + | sort -u \ |
| 51 | + | xargs -rt apt-mark manual; \ |
| 52 | + \ |
| 53 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 54 | + rm -rf /var/lib/apt/lists/* |
| 55 | + |
| 56 | +# set recommended PHP.ini settings |
| 57 | +# see https://secure.php.net/manual/en/opcache.installation.php |
| 58 | +RUN { \ |
| 59 | + echo 'opcache.memory_consumption=128'; \ |
| 60 | + echo 'opcache.interned_strings_buffer=8'; \ |
| 61 | + echo 'opcache.max_accelerated_files=4000'; \ |
| 62 | + echo 'opcache.revalidate_freq=2'; \ |
| 63 | + echo 'opcache.fast_shutdown=1'; \ |
| 64 | + } > /usr/local/etc/php/conf.d/opcache-recommended.ini |
| 65 | +# https://wordpress.org/support/article/editing-wp-config-php/#configure-error-logging |
| 66 | +RUN { \ |
| 67 | +# https://www.php.net/manual/en/errorfunc.constants.php |
| 68 | +# https://github.com/docker-library/wordpress/issues/420#issuecomment-517839670 |
| 69 | + echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \ |
| 70 | + echo 'display_errors = Off'; \ |
| 71 | + echo 'display_startup_errors = Off'; \ |
| 72 | + echo 'log_errors = On'; \ |
| 73 | + echo 'error_log = /dev/stderr'; \ |
| 74 | + echo 'log_errors_max_len = 1024'; \ |
| 75 | + echo 'ignore_repeated_errors = On'; \ |
| 76 | + echo 'ignore_repeated_source = Off'; \ |
| 77 | + echo 'html_errors = Off'; \ |
| 78 | + } > /usr/local/etc/php/conf.d/error-logging.ini |
| 79 | + |
| 80 | +RUN set -eux; \ |
| 81 | + a2enmod rewrite expires; \ |
| 82 | + \ |
| 83 | +# https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html |
| 84 | + a2enmod remoteip; \ |
| 85 | + { \ |
| 86 | + echo 'RemoteIPHeader X-Forwarded-For'; \ |
| 87 | +# these IP ranges are reserved for "private" use and should thus *usually* be safe inside Docker |
| 88 | + echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \ |
| 89 | + echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \ |
| 90 | + echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \ |
| 91 | + echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \ |
| 92 | + echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \ |
| 93 | + } > /etc/apache2/conf-available/remoteip.conf; \ |
| 94 | + a2enconf remoteip; \ |
| 95 | +# https://github.com/docker-library/wordpress/issues/383#issuecomment-507886512 |
| 96 | +# (replace all instances of "%h" with "%a" in LogFormat) |
| 97 | + find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' + |
| 98 | + |
| 99 | +VOLUME /var/www/html |
| 100 | + |
| 101 | +ENV WORDPRESS_VERSION 5.3 |
| 102 | +ENV WORDPRESS_SHA1 e3edcb1131e539c2b2e10fed37f8b6683c824a98 |
| 103 | + |
| 104 | +RUN set -ex; \ |
| 105 | + curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \ |
| 106 | + echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \ |
| 107 | +# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress |
| 108 | + tar -xzf wordpress.tar.gz -C /usr/src/; \ |
| 109 | + rm wordpress.tar.gz; \ |
| 110 | + chown -R www-data:www-data /usr/src/wordpress |
| 111 | + |
| 112 | +COPY docker-entrypoint.sh /usr/local/bin/ |
| 113 | + |
| 114 | +ENTRYPOINT ["docker-entrypoint.sh"] |
| 115 | +CMD ["apache2-foreground"] |
0 commit comments