Dockerfile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. FROM php:8.2-apache
  2. # persistent dependencies
  3. RUN set -eux; \
  4. apt-get update; \
  5. apt-get install -y --no-install-recommends \
  6. # Ghostscript is required for rendering PDF previews
  7. ghostscript \
  8. ; \
  9. rm -rf /var/lib/apt/lists/*
  10. # install the PHP extensions we need (https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions)
  11. RUN set -ex; \
  12. \
  13. savedAptMark="$(apt-mark showmanual)"; \
  14. \
  15. apt-get update; \
  16. apt-get install -y --no-install-recommends \
  17. libfreetype6-dev \
  18. libicu-dev \
  19. libjpeg-dev \
  20. libmagickwand-dev \
  21. libpng-dev \
  22. libwebp-dev \
  23. libzip-dev \
  24. ; \
  25. \
  26. docker-php-ext-configure gd \
  27. --with-freetype \
  28. --with-jpeg \
  29. --with-webp \
  30. ; \
  31. docker-php-ext-install -j "$(nproc)" \
  32. bcmath \
  33. exif \
  34. gd \
  35. intl \
  36. mysqli \
  37. zip \
  38. ; \
  39. # https://pecl.php.net/package/imagick
  40. pecl install imagick-3.6.0; \
  41. docker-php-ext-enable imagick; \
  42. rm -r /tmp/pear; \
  43. \
  44. # some misbehaving extensions end up outputting to stdout 🙈 (https://github.com/docker-library/wordpress/issues/669#issuecomment-993945967)
  45. out="$(php -r 'exit(0);')"; \
  46. [ -z "$out" ]; \
  47. err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; \
  48. [ -z "$err" ]; \
  49. \
  50. extDir="$(php -r 'echo ini_get("extension_dir");')"; \
  51. [ -d "$extDir" ]; \
  52. # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
  53. apt-mark auto '.*' > /dev/null; \
  54. apt-mark manual $savedAptMark; \
  55. ldd "$extDir"/*.so \
  56. | awk '/=>/ { print $3 }' \
  57. | sort -u \
  58. | xargs -r dpkg-query -S \
  59. | cut -d: -f1 \
  60. | sort -u \
  61. | xargs -rt apt-mark manual; \
  62. \
  63. apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
  64. rm -rf /var/lib/apt/lists/*; \
  65. \
  66. ! { ldd "$extDir"/*.so | grep 'not found'; }; \
  67. # check for output like "PHP Warning: PHP Startup: Unable to load dynamic library 'foo' (tried: ...)
  68. err="$(php --version 3>&1 1>&2 2>&3)"; \
  69. [ -z "$err" ]
  70. # set recommended PHP.ini settings
  71. # see https://secure.php.net/manual/en/opcache.installation.php
  72. RUN set -eux; \
  73. docker-php-ext-enable opcache; \
  74. { \
  75. echo 'opcache.memory_consumption=128'; \
  76. echo 'opcache.interned_strings_buffer=8'; \
  77. echo 'opcache.max_accelerated_files=4000'; \
  78. echo 'opcache.revalidate_freq=2'; \
  79. } > /usr/local/etc/php/conf.d/opcache-recommended.ini
  80. # https://wordpress.org/support/article/editing-wp-config-php/#configure-error-logging
  81. RUN { \
  82. # https://www.php.net/manual/en/errorfunc.constants.php
  83. # https://github.com/docker-library/wordpress/issues/420#issuecomment-517839670
  84. echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
  85. echo 'display_errors = Off'; \
  86. echo 'display_startup_errors = Off'; \
  87. echo 'log_errors = On'; \
  88. echo 'error_log = /dev/stderr'; \
  89. echo 'log_errors_max_len = 1024'; \
  90. echo 'ignore_repeated_errors = On'; \
  91. echo 'ignore_repeated_source = Off'; \
  92. echo 'html_errors = Off'; \
  93. } > /usr/local/etc/php/conf.d/error-logging.ini
  94. RUN set -eux; \
  95. a2enmod rewrite expires; \
  96. \
  97. # https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html
  98. a2enmod remoteip; \
  99. { \
  100. echo 'RemoteIPHeader X-Forwarded-For'; \
  101. # these IP ranges are reserved for "private" use and should thus *usually* be safe inside Docker
  102. echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \
  103. echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \
  104. echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \
  105. echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \
  106. echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \
  107. } > /etc/apache2/conf-available/remoteip.conf; \
  108. a2enconf remoteip; \
  109. # https://github.com/docker-library/wordpress/issues/383#issuecomment-507886512
  110. # (replace all instances of "%h" with "%a" in LogFormat)
  111. find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
  112. RUN set -eux; \
  113. version='6.2'; \
  114. sha1='6fcc4c21b107a355e3df0798851d41e0d85f0e6d'; \
  115. \
  116. curl -o wordpress.tar.gz -fL "https://wordpress.org/wordpress-$version.tar.gz"; \
  117. echo "$sha1 *wordpress.tar.gz" | sha1sum -c -; \
  118. \
  119. # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
  120. tar -xzf wordpress.tar.gz -C /usr/src/; \
  121. rm wordpress.tar.gz; \
  122. \
  123. # https://wordpress.org/support/article/htaccess/
  124. [ ! -e /usr/src/wordpress/.htaccess ]; \
  125. { \
  126. echo '# BEGIN WordPress'; \
  127. echo ''; \
  128. echo 'RewriteEngine On'; \
  129. echo 'RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]'; \
  130. echo 'RewriteBase /'; \
  131. echo 'RewriteRule ^index\.php$ - [L]'; \
  132. echo 'RewriteCond %{REQUEST_FILENAME} !-f'; \
  133. echo 'RewriteCond %{REQUEST_FILENAME} !-d'; \
  134. echo 'RewriteRule . /index.php [L]'; \
  135. echo ''; \
  136. echo '# END WordPress'; \
  137. } > /usr/src/wordpress/.htaccess; \
  138. \
  139. chown -R www-data:www-data /usr/src/wordpress; \
  140. # pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
  141. # wp-content/cache: https://github.com/docker-library/wordpress/issues/534#issuecomment-705733507
  142. mkdir wp-content; \
  143. for dir in /usr/src/wordpress/wp-content/*/ cache; do \
  144. dir="$(basename "${dir%/}")"; \
  145. mkdir "wp-content/$dir"; \
  146. done; \
  147. chown -R www-data:www-data wp-content; \
  148. chmod -R 1777 wp-content
  149. VOLUME /var/www/html
  150. COPY --chown=www-data:www-data rootfs/wp-config-docker.php /usr/src/wordpress/
  151. COPY rootfs/docker-entrypoint.sh /usr/local/bin/
  152. RUN chmod +x /usr/local/bin/docker-entrypoint.sh
  153. ENTRYPOINT ["docker-entrypoint.sh"]
  154. CMD ["apache2-foreground"]