You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
8.9 KiB

  1. #
  2. # NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
  3. #
  4. # PLEASE DO NOT EDIT IT DIRECTLY.
  5. #
  6. FROM debian:buster-slim
  7. ARG PHP_APACHE_WWW_DATA_UID=33
  8. ARG PHP_APACHE_WWW_DATA_GID=33
  9. RUN groupmod -g $PHP_APACHE_WWW_DATA_GID www-data; \
  10. usermod -u $PHP_APACHE_WWW_DATA_UID -g $PHP_APACHE_WWW_DATA_GID www-data
  11. # prevent Debian's PHP packages from being installed
  12. # https://github.com/docker-library/php/pull/542
  13. RUN set -eux; \
  14. { \
  15. echo 'Package: php*'; \
  16. echo 'Pin: release *'; \
  17. echo 'Pin-Priority: -1'; \
  18. } > /etc/apt/preferences.d/no-debian-php
  19. # dependencies required for running "phpize"
  20. # (see persistent deps below)
  21. ENV PHPIZE_DEPS \
  22. autoconf \
  23. dpkg-dev \
  24. file \
  25. g++ \
  26. gcc \
  27. libc-dev \
  28. make \
  29. pkg-config \
  30. re2c
  31. # persistent / runtime deps
  32. RUN set -eux; \
  33. apt-get update; \
  34. apt-get install -y --no-install-recommends \
  35. $PHPIZE_DEPS \
  36. ca-certificates \
  37. curl \
  38. xz-utils \
  39. ; \
  40. rm -rf /var/lib/apt/lists/*
  41. ENV PHP_INI_DIR /usr/local/etc/php
  42. RUN set -eux; \
  43. mkdir -p "$PHP_INI_DIR/conf.d"; \
  44. # allow running as an arbitrary user (https://github.com/docker-library/php/issues/743)
  45. [ ! -d /var/www/html ]; \
  46. mkdir -p /var/www/html; \
  47. chown www-data:www-data /var/www/html; \
  48. chmod 777 /var/www/html
  49. ENV APACHE_CONFDIR /etc/apache2
  50. ENV APACHE_ENVVARS $APACHE_CONFDIR/envvars
  51. RUN set -eux; \
  52. apt-get update; \
  53. apt-get install -y --no-install-recommends apache2; \
  54. rm -rf /var/lib/apt/lists/*; \
  55. \
  56. # generically convert lines like
  57. # export APACHE_RUN_USER=www-data
  58. # into
  59. # : ${APACHE_RUN_USER:=www-data}
  60. # export APACHE_RUN_USER
  61. # so that they can be overridden at runtime ("-e APACHE_RUN_USER=...")
  62. sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS"; \
  63. \
  64. # setup directories and permissions
  65. . "$APACHE_ENVVARS"; \
  66. for dir in \
  67. "$APACHE_LOCK_DIR" \
  68. "$APACHE_RUN_DIR" \
  69. "$APACHE_LOG_DIR" \
  70. ; do \
  71. rm -rvf "$dir"; \
  72. mkdir -p "$dir"; \
  73. chown "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"; \
  74. # allow running as an arbitrary user (https://github.com/docker-library/php/issues/743)
  75. chmod 777 "$dir"; \
  76. done; \
  77. \
  78. # delete the "index.html" that installing Apache drops in here
  79. rm -rvf /var/www/html/*; \
  80. \
  81. # logs should go to stdout / stderr
  82. ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log"; \
  83. ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log"; \
  84. ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
  85. chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
  86. # Apache + PHP requires preforking Apache for best results
  87. RUN a2dismod mpm_event && a2enmod mpm_prefork
  88. # PHP files should be handled by PHP, and should be preferred over any other file type
  89. RUN { \
  90. echo '<FilesMatch \.php$>'; \
  91. echo '\tSetHandler application/x-httpd-php'; \
  92. echo '</FilesMatch>'; \
  93. echo; \
  94. echo 'DirectoryIndex disabled'; \
  95. echo 'DirectoryIndex index.php index.html'; \
  96. echo; \
  97. echo '<Directory /var/www/>'; \
  98. echo '\tOptions -Indexes'; \
  99. echo '\tAllowOverride All'; \
  100. echo '</Directory>'; \
  101. } | tee "$APACHE_CONFDIR/conf-available/docker-php.conf" \
  102. && a2enconf docker-php
  103. # Apply stack smash protection to functions using local buffers and alloca()
  104. # Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64)
  105. # Enable optimization (-O2)
  106. # Enable linker optimization (this sorts the hash buckets to improve cache locality, and is non-default)
  107. # https://github.com/docker-library/php/issues/272
  108. # -D_LARGEFILE_SOURCE and -D_FILE_OFFSET_BITS=64 (https://www.php.net/manual/en/intro.filesystem.php)
  109. ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
  110. ENV PHP_CPPFLAGS="$PHP_CFLAGS"
  111. ENV PHP_LDFLAGS="-Wl,-O1 -pie"
  112. ENV GPG_KEYS 42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312
  113. ENV PHP_VERSION 7.4.24
  114. ENV PHP_URL="https://www.php.net/distributions/php-7.4.24.tar.xz" PHP_ASC_URL="https://www.php.net/distributions/php-7.4.24.tar.xz.asc"
  115. ENV PHP_SHA256="ff7658ee2f6d8af05b48c21146af5f502e121def4e76e862df5ec9fa06e98734"
  116. RUN set -eux; \
  117. \
  118. savedAptMark="$(apt-mark showmanual)"; \
  119. apt-get update; \
  120. apt-get install -y --no-install-recommends gnupg dirmngr; \
  121. rm -rf /var/lib/apt/lists/*; \
  122. \
  123. mkdir -p /usr/src; \
  124. cd /usr/src; \
  125. \
  126. curl -fsSL -o php.tar.xz "$PHP_URL"; \
  127. \
  128. if [ -n "$PHP_SHA256" ]; then \
  129. echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
  130. fi; \
  131. \
  132. if [ -n "$PHP_ASC_URL" ]; then \
  133. curl -fsSL -o php.tar.xz.asc "$PHP_ASC_URL"; \
  134. export GNUPGHOME="$(mktemp -d)"; \
  135. for key in $GPG_KEYS; do \
  136. gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
  137. done; \
  138. gpg --batch --verify php.tar.xz.asc php.tar.xz; \
  139. gpgconf --kill all; \
  140. rm -rf "$GNUPGHOME"; \
  141. fi; \
  142. \
  143. apt-mark auto '.*' > /dev/null; \
  144. apt-mark manual $savedAptMark > /dev/null; \
  145. apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
  146. COPY docker-php-source /usr/local/bin/
  147. RUN set -eux; \
  148. \
  149. savedAptMark="$(apt-mark showmanual)"; \
  150. apt-get update; \
  151. apt-get install -y --no-install-recommends \
  152. apache2-dev \
  153. libargon2-dev \
  154. libcurl4-openssl-dev \
  155. libonig-dev \
  156. libreadline-dev \
  157. libsodium-dev \
  158. libsqlite3-dev \
  159. libssl-dev \
  160. libxml2-dev \
  161. zlib1g-dev \
  162. ; \
  163. \
  164. export \
  165. CFLAGS="$PHP_CFLAGS" \
  166. CPPFLAGS="$PHP_CPPFLAGS" \
  167. LDFLAGS="$PHP_LDFLAGS" \
  168. ; \
  169. docker-php-source extract; \
  170. cd /usr/src/php; \
  171. gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
  172. debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
  173. # https://bugs.php.net/bug.php?id=74125
  174. if [ ! -d /usr/include/curl ]; then \
  175. ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \
  176. fi; \
  177. ./configure \
  178. --build="$gnuArch" \
  179. --with-config-file-path="$PHP_INI_DIR" \
  180. --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
  181. \
  182. # make sure invalid --configure-flags are fatal errors instead of just warnings
  183. --enable-option-checking=fatal \
  184. \
  185. # https://github.com/docker-library/php/issues/439
  186. --with-mhash \
  187. \
  188. # https://github.com/docker-library/php/issues/822
  189. --with-pic \
  190. \
  191. # --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
  192. --enable-ftp \
  193. # --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
  194. --enable-mbstring \
  195. # --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
  196. --enable-mysqlnd \
  197. # https://wiki.php.net/rfc/argon2_password_hash
  198. --with-password-argon2 \
  199. # https://wiki.php.net/rfc/libsodium
  200. --with-sodium=shared \
  201. # always build against system sqlite3 (https://github.com/php/php-src/commit/6083a387a81dbbd66d6316a3a12a63f06d5f7109)
  202. --with-pdo-sqlite=/usr \
  203. --with-sqlite3=/usr \
  204. \
  205. --with-curl \
  206. --with-openssl \
  207. --with-readline \
  208. --with-zlib \
  209. \
  210. # in PHP 7.4+, the pecl/pear installers are officially deprecated (requiring an explicit "--with-pear")
  211. --with-pear \
  212. \
  213. # bundled pcre does not support JIT on s390x
  214. # https://manpages.debian.org/bullseye/libpcre3-dev/pcrejit.3.en.html#AVAILABILITY_OF_JIT_SUPPORT
  215. $(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \
  216. --with-libdir="lib/$debMultiarch" \
  217. \
  218. --disable-cgi \
  219. \
  220. --with-apxs2 \
  221. ; \
  222. make -j "$(nproc)"; \
  223. find -type f -name '*.a' -delete; \
  224. make install; \
  225. find \
  226. /usr/local \
  227. -type f \
  228. -perm '/0111' \
  229. -exec sh -euxc ' \
  230. strip --strip-all "$@" || : \
  231. ' -- '{}' + \
  232. ; \
  233. make clean; \
  234. \
  235. # https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable)
  236. cp -v php.ini-* "$PHP_INI_DIR/"; \
  237. \
  238. cd /; \
  239. docker-php-source delete; \
  240. \
  241. # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
  242. apt-mark auto '.*' > /dev/null; \
  243. [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
  244. find /usr/local -type f -executable -exec ldd '{}' ';' \
  245. | awk '/=>/ { print $(NF-1) }' \
  246. | sort -u \
  247. | xargs -r dpkg-query --search \
  248. | cut -d: -f1 \
  249. | sort -u \
  250. | xargs -r apt-mark manual \
  251. ; \
  252. apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
  253. rm -rf /var/lib/apt/lists/*; \
  254. \
  255. # update pecl channel definitions https://github.com/docker-library/php/issues/443
  256. pecl update-channels; \
  257. rm -rf /tmp/pear ~/.pearrc; \
  258. \
  259. # smoke test
  260. php --version
  261. COPY docker-php-ext-* docker-php-entrypoint /usr/local/bin/
  262. # sodium was built as a shared module (so that it can be replaced later if so desired), so let's enable it too (https://github.com/docker-library/php/issues/598)
  263. RUN docker-php-ext-enable sodium
  264. ENTRYPOINT ["docker-php-entrypoint"]
  265. # https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
  266. STOPSIGNAL SIGWINCH
  267. COPY apache2-foreground /usr/local/bin/
  268. WORKDIR /var/www/html
  269. EXPOSE 80
  270. CMD ["apache2-foreground"]