forked from gh-mirrors/docker-php-5.3
Add PHP compilation flags, reorganize dep install steps, add MySQL support, improve image size, fix permission issues
This commit is contained in:
169
Dockerfile
169
Dockerfile
@@ -1,5 +1,5 @@
|
|||||||
FROM ubuntu:bionic as openssl-build
|
FROM ubuntu:bionic as openssl-build
|
||||||
MAINTAINER Hans Rakers <h.rakers@global.leaseweb.com>
|
LABEL maintainer="Hans Rakers <h.rakers@global.leaseweb.com>"
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
@@ -80,34 +80,40 @@ FROM ubuntu:bionic as php-build
|
|||||||
COPY --from=openssl-build "/usr/local/ssl/" "/usr/local/ssl/"
|
COPY --from=openssl-build "/usr/local/ssl/" "/usr/local/ssl/"
|
||||||
COPY --from=curl-build "/usr/local/curl/" "/usr/local/curl/"
|
COPY --from=curl-build "/usr/local/curl/" "/usr/local/curl/"
|
||||||
|
|
||||||
# persistent / runtime deps
|
# build dependencies for php-5.3
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
# php 5.3 needs older autoconf
|
||||||
ca-certificates \
|
|
||||||
curl \
|
|
||||||
librecode0 \
|
|
||||||
libsqlite3-0 \
|
|
||||||
libxml2 \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# phpize deps
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
autoconf \
|
autoconf \
|
||||||
|
autoconf2.13 \
|
||||||
|
ca-certificates \
|
||||||
|
curl \
|
||||||
file \
|
file \
|
||||||
g++ \
|
g++ \
|
||||||
gcc \
|
gcc \
|
||||||
gnupg \
|
gnupg \
|
||||||
|
libbz2-dev \
|
||||||
libc-dev \
|
libc-dev \
|
||||||
|
libedit-dev \
|
||||||
|
libidn2-dev \
|
||||||
|
libmcrypt-dev \
|
||||||
|
libnghttp2-dev \
|
||||||
|
libpsl-dev \
|
||||||
|
libreadline6-dev \
|
||||||
|
librecode-dev \
|
||||||
|
libsqlite3-dev \
|
||||||
|
libssl-dev \
|
||||||
|
libxml2-dev \
|
||||||
make \
|
make \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
re2c \
|
re2c \
|
||||||
|
xz-utils \
|
||||||
|
zlib1g-dev \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
ENV PHP_INI_DIR /usr/local/etc/php
|
ENV PHP_INI_DIR /usr/local/etc/php
|
||||||
RUN mkdir -p $PHP_INI_DIR/conf.d
|
|
||||||
|
|
||||||
ENV GPG_KEYS 0B96609E270F565C13292B24C13C70B87267B52D 0A95E9A026542D53835E3F3A7DEC4E69FC9C83D7
|
ENV GPG_KEYS 0B96609E270F565C13292B24C13C70B87267B52D 0A95E9A026542D53835E3F3A7DEC4E69FC9C83D7 A4A9406876FCBD3C456770C88C718D3B5072E1F5
|
||||||
RUN set -xe \
|
RUN set -xe \
|
||||||
&& mkdir ~/.gnupg && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
|
&& mkdir ~/.gnupg && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
|
||||||
&& for key in $GPG_KEYS; do \
|
&& for key in $GPG_KEYS; do \
|
||||||
@@ -116,31 +122,43 @@ RUN set -xe \
|
|||||||
|
|
||||||
ENV PHP_VERSION 5.3.29
|
ENV PHP_VERSION 5.3.29
|
||||||
|
|
||||||
# php 5.3 needs older autoconf
|
ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --disable-cgi
|
||||||
|
|
||||||
|
# Apply stack smash protection to functions using local buffers and alloca()
|
||||||
|
# Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64)
|
||||||
|
# Enable optimization (-O2)
|
||||||
|
# Enable linker optimization (this sorts the hash buckets to improve cache locality, and is non-default)
|
||||||
|
# https://github.com/docker-library/php/issues/272
|
||||||
|
# -D_LARGEFILE_SOURCE and -D_FILE_OFFSET_BITS=64 (https://www.php.net/manual/en/intro.filesystem.php)
|
||||||
|
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
|
||||||
|
ENV PHP_CPPFLAGS="$PHP_CFLAGS"
|
||||||
|
ENV PHP_LDFLAGS="-Wl,-O1 -pie"
|
||||||
|
|
||||||
|
COPY docker-php-source /usr/local/bin/
|
||||||
|
|
||||||
# --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself)
|
# --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself)
|
||||||
RUN buildDeps=" \
|
RUN set -eux \
|
||||||
autoconf2.13 \
|
# Install MySQL 5.7 client library and headers (the system package is compiled against OpenSSL 1.1, which we can't use)
|
||||||
libbz2-dev \
|
&& cd /usr/src \
|
||||||
libidn2-dev \
|
&& curl -SL "http://mirror.nl.leaseweb.net/mysql/Downloads/MySQL-5.7/libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb" -o libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb \
|
||||||
libmcrypt-dev \
|
&& curl -SL "http://mirror.nl.leaseweb.net/mysql/Downloads/MySQL-5.7/libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb.asc" -o libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb.asc \
|
||||||
libnghttp2-dev \
|
&& curl -SL "http://mirror.nl.leaseweb.net/mysql/Downloads/MySQL-5.7/libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb" -o libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb \
|
||||||
libpsl-dev \
|
&& curl -SL "http://mirror.nl.leaseweb.net/mysql/Downloads/MySQL-5.7/libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb.asc" -o libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb.asc \
|
||||||
libreadline6-dev \
|
&& curl -SL "http://mirror.nl.leaseweb.net/mysql/Downloads/MySQL-5.7/mysql-common_5.7.30-1ubuntu18.04_amd64.deb" -o mysql-common_5.7.30-1ubuntu18.04_amd64.deb \
|
||||||
librecode-dev \
|
&& curl -SL "http://mirror.nl.leaseweb.net/mysql/Downloads/MySQL-5.7/mysql-common_5.7.30-1ubuntu18.04_amd64.deb.asc" -o mysql-common_5.7.30-1ubuntu18.04_amd64.deb.asc \
|
||||||
libsqlite3-dev \
|
&& gpg --verify libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb.asc \
|
||||||
libssl-dev \
|
&& gpg --verify libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb.asc \
|
||||||
libxml2-dev \
|
&& gpg --verify mysql-common_5.7.30-1ubuntu18.04_amd64.deb.asc \
|
||||||
xz-utils \
|
&& dpkg -i libmysqlclient-dev_5.7.30-1ubuntu18.04_amd64.deb libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb mysql-common_5.7.30-1ubuntu18.04_amd64.deb \
|
||||||
" \
|
|
||||||
&& set -x \
|
|
||||||
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
|
|
||||||
&& curl -SL "http://nl.php.net/get/php-$PHP_VERSION.tar.xz/from/this/mirror" -o php.tar.xz \
|
&& curl -SL "http://nl.php.net/get/php-$PHP_VERSION.tar.xz/from/this/mirror" -o php.tar.xz \
|
||||||
&& curl -SL "http://nl.php.net/get/php-$PHP_VERSION.tar.xz.asc/from/this/mirror" -o php.tar.xz.asc \
|
&& curl -SL "http://nl.php.net/get/php-$PHP_VERSION.tar.xz.asc/from/this/mirror" -o php.tar.xz.asc \
|
||||||
&& gpg --verify php.tar.xz.asc \
|
&& gpg --verify php.tar.xz.asc \
|
||||||
&& mkdir -p /usr/src/php \
|
&& docker-php-source extract \
|
||||||
&& tar -xof php.tar.xz -C /usr/src/php --strip-components=1 \
|
|
||||||
&& rm php.tar.xz* \
|
|
||||||
&& cd /usr/src/php \
|
&& cd /usr/src/php \
|
||||||
|
&& export \
|
||||||
|
CFLAGS="$PHP_CFLAGS" \
|
||||||
|
CPPFLAGS="$PHP_CPPFLAGS" \
|
||||||
|
LDFLAGS="$PHP_LDFLAGS" \
|
||||||
&& ./configure \
|
&& ./configure \
|
||||||
--with-config-file-path="$PHP_INI_DIR" \
|
--with-config-file-path="$PHP_INI_DIR" \
|
||||||
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
|
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
|
||||||
@@ -157,41 +175,89 @@ RUN buildDeps=" \
|
|||||||
--with-gettext \
|
--with-gettext \
|
||||||
--with-mcrypt \
|
--with-mcrypt \
|
||||||
--with-mhash \
|
--with-mhash \
|
||||||
|
--with-mysql \
|
||||||
|
--with-pdo-mysql \
|
||||||
|
--with-pdo-sqlite=/usr \
|
||||||
|
--with-sqlite3=/usr \
|
||||||
|
--with-libedit \
|
||||||
|
--with-zlib \
|
||||||
--enable-bcmath \
|
--enable-bcmath \
|
||||||
--enable-ftp \
|
--enable-ftp \
|
||||||
--enable-intl \
|
--enable-intl \
|
||||||
--enable-mbstring \
|
--enable-mbstring \
|
||||||
|
--enable-mysqlnd \
|
||||||
--enable-soap \
|
--enable-soap \
|
||||||
--enable-zip \
|
--enable-zip \
|
||||||
|
${PHP_EXTRA_CONFIGURE_ARGS:-} \
|
||||||
&& sed -i '/EXTRA_LIBS = /s|$| -lstdc++|' Makefile \
|
&& sed -i '/EXTRA_LIBS = /s|$| -lstdc++|' Makefile \
|
||||||
&& make -j$(nproc)
|
&& make -j$(nproc) \
|
||||||
|
&& find -type f -name '*.a' -delete
|
||||||
|
|
||||||
FROM ubuntu:bionic
|
FROM ubuntu:bionic
|
||||||
|
|
||||||
# persistent / runtime deps
|
COPY --from=php-build "/usr/src/" "/usr/src/"
|
||||||
|
|
||||||
|
COPY docker-php-* /usr/local/bin/
|
||||||
|
|
||||||
|
# prevent Debian's PHP packages from being installed
|
||||||
|
# https://github.com/docker-library/php/pull/542
|
||||||
|
RUN set -eux; \
|
||||||
|
{ \
|
||||||
|
echo 'Package: php*'; \
|
||||||
|
echo 'Pin: release *'; \
|
||||||
|
echo 'Pin-Priority: -1'; \
|
||||||
|
} > /etc/apt/preferences.d/no-debian-php
|
||||||
|
|
||||||
|
# persistent / runtime deps and deps required for compiling extensions
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
autoconf \
|
||||||
binutils \
|
binutils \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
libcurl3 \
|
curl \
|
||||||
|
file \
|
||||||
|
g++ \
|
||||||
|
gcc \
|
||||||
|
gnupg \
|
||||||
|
libc-dev \
|
||||||
|
libedit2 \
|
||||||
|
libidn2-0 \
|
||||||
|
libnghttp2-14 \
|
||||||
librecode0 \
|
librecode0 \
|
||||||
libmcrypt4 \
|
libmcrypt4 \
|
||||||
|
libpsl5 \
|
||||||
libreadline7 \
|
libreadline7 \
|
||||||
libsqlite3-0 \
|
libsqlite3-0 \
|
||||||
libxml2 \
|
libxml2 \
|
||||||
make \
|
make \
|
||||||
|
pkg-config \
|
||||||
|
re2c \
|
||||||
|
xz-utils \
|
||||||
|
# Install MySQL 5.7 client library and headers (the system package is compiled against OpenSSL 1.1)
|
||||||
|
&& cd /usr/src \
|
||||||
|
&& dpkg -i libmysqlclient20_5.7.30-1ubuntu18.04_amd64.deb mysql-common_5.7.30-1ubuntu18.04_amd64.deb \
|
||||||
|
&& rm /usr/src/*amd64.deb* \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY --from=php-build "/usr/src/php/" "/usr/src/php/"
|
ENV PHP_INI_DIR /usr/local/etc/php
|
||||||
COPY --from=php-build "/usr/local/etc/php/" "/usr/local/etc/php/"
|
|
||||||
|
|
||||||
RUN cd /usr/src/php \
|
RUN set -eux; \
|
||||||
&& make install \
|
mkdir -p "$PHP_INI_DIR/conf.d"; \
|
||||||
&& { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
|
# allow running as an arbitrary user (https://github.com/docker-library/php/issues/743)
|
||||||
&& make clean
|
[ ! -d /var/www/html ]; \
|
||||||
|
mkdir -p /var/www/html; \
|
||||||
# COPY --from=php-build "/usr/local/php/" "/usr/local/"
|
chown www-data:www-data /var/www/html; \
|
||||||
COPY docker-php-* /usr/local/bin/
|
chmod 777 /var/www/html; \
|
||||||
|
cd /usr/src/php; \
|
||||||
|
make install; \
|
||||||
|
{ find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; }; \
|
||||||
|
make clean; \
|
||||||
|
cp -v php.ini-* "$PHP_INI_DIR/"; \
|
||||||
|
cd /; \
|
||||||
|
docker-php-source delete; \
|
||||||
|
pecl update-channels; \
|
||||||
|
rm -rf /tmp/pear ~/.pearrc; \
|
||||||
|
php --version
|
||||||
|
|
||||||
ENTRYPOINT ["docker-php-entrypoint"]
|
ENTRYPOINT ["docker-php-entrypoint"]
|
||||||
WORKDIR /var/www/html
|
WORKDIR /var/www/html
|
||||||
@@ -221,6 +287,8 @@ RUN set -ex \
|
|||||||
echo '; if we send this to /proc/self/fd/1, it never appears'; \
|
echo '; if we send this to /proc/self/fd/1, it never appears'; \
|
||||||
echo 'access.log = /proc/self/fd/2'; \
|
echo 'access.log = /proc/self/fd/2'; \
|
||||||
echo; \
|
echo; \
|
||||||
|
echo 'clear_env = no'; \
|
||||||
|
echo; \
|
||||||
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
|
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
|
||||||
echo 'catch_workers_output = yes'; \
|
echo 'catch_workers_output = yes'; \
|
||||||
} | tee php-fpm.d/docker.conf \
|
} | tee php-fpm.d/docker.conf \
|
||||||
@@ -230,13 +298,14 @@ RUN set -ex \
|
|||||||
echo; \
|
echo; \
|
||||||
echo '[www]'; \
|
echo '[www]'; \
|
||||||
echo 'listen = 9000'; \
|
echo 'listen = 9000'; \
|
||||||
} | tee php-fpm.d/zz-docker.conf \
|
} | tee php-fpm.d/zz-docker.conf
|
||||||
&& pecl update-channels \
|
|
||||||
&& rm -rf /tmp/pear ~/.pearrc \
|
|
||||||
&& php --version
|
|
||||||
|
|
||||||
# fix some weird corruption in this file
|
# fix some weird corruption in this file
|
||||||
RUN sed -i -e "" /usr/local/etc/php-fpm.d/www.conf
|
RUN sed -i -e "" /usr/local/etc/php-fpm.d/www.conf
|
||||||
|
|
||||||
|
# Override stop signal to stop process gracefully
|
||||||
|
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
|
||||||
|
STOPSIGNAL SIGQUIT
|
||||||
|
|
||||||
EXPOSE 9000
|
EXPOSE 9000
|
||||||
CMD ["php-fpm"]
|
CMD ["php-fpm"]
|
||||||
|
|||||||
Reference in New Issue
Block a user