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.

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