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