Skip to content

Commit 8a319e2

Browse files
update Dockerfile
1 parent d2b8a9a commit 8a319e2

1 file changed

Lines changed: 97 additions & 92 deletions

File tree

php/7.2.34/Dockerfile

Lines changed: 97 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -88,98 +88,103 @@ COPY ./data/php-7.2.34.tar.xz /usr/src/php.tar.xz
8888
COPY --from=php-source /usr/local/bin/docker-php-source /usr/local/bin/
8989

9090

91-
# 第一阶段: 准备编译环境
92-
RUN set -eux && \
93-
savedAptMark="$(apt-mark showmanual)" && \
94-
apt-get update && \
95-
apt-get install -y --no-install-recommends \
96-
libargon2-dev \
97-
libcurl4-openssl-dev \
98-
libedit-dev \
99-
libsodium-dev \
100-
libsqlite3-dev \
101-
libssl-dev \
102-
libxml2-dev \
103-
zlib1g-dev \
104-
${PHP_EXTRA_BUILD_DEPS:-} && \
105-
rm -rf /var/lib/apt/lists/* && \
106-
echo "Build dependencies installed successfully"
107-
108-
# 第二阶段: 提取源码并配置
109-
RUN set -eux && \
110-
export CFLAGS="$PHP_CFLAGS" && \
111-
export CPPFLAGS="$PHP_CPPFLAGS" && \
112-
export LDFLAGS="$PHP_LDFLAGS" && \
113-
docker-php-source extract && \
114-
cd /usr/src/php && \
115-
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" && \
116-
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)" && \
117-
echo "Architecture: $gnuArch, Multiarch: $debMultiarch"
118-
119-
# 第三阶段: 修复curl路径并配置编译
120-
RUN set -eux && \
121-
cd /usr/src/php && \
122-
export CFLAGS="$PHP_CFLAGS" && \
123-
export CPPFLAGS="$PHP_CPPFLAGS" && \
124-
export LDFLAGS="$PHP_LDFLAGS" && \
125-
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" && \
126-
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)" && \
127-
if [ ! -d /usr/include/curl ]; then \
128-
ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \
129-
fi && \
130-
./configure \
131-
--build="$gnuArch" \
132-
--with-config-file-path="$PHP_INI_DIR" \
133-
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
134-
--enable-option-checking=fatal \
135-
--with-mhash \
136-
--enable-ftp \
137-
--enable-mbstring \
138-
--enable-mysqlnd \
139-
--with-password-argon2 \
140-
--with-sodium=shared \
141-
--with-pdo-sqlite=/usr \
142-
--with-sqlite3=/usr \
143-
--with-curl \
144-
--with-libedit \
145-
--with-openssl \
146-
--with-zlib \
147-
$(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \
148-
--with-libdir="lib/$debMultiarch" \
149-
${PHP_EXTRA_CONFIGURE_ARGS:-}
150-
151-
# 第四阶段: 编译和安装
152-
RUN set -eux && \
153-
cd /usr/src/php && \
154-
make -j "$(nproc)" && \
155-
find . -type f -name '*.a' -delete && \
156-
make install && \
157-
find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true && \
158-
make clean && \
159-
cp -v php.ini-* "$PHP_INI_DIR/"
160-
161-
# 第五阶段: 清理和优化
162-
RUN set -eux && \
163-
cd / && \
164-
docker-php-source delete && \
165-
savedAptMark="$(apt-mark showmanual)" && \
166-
apt-mark auto '.*' > /dev/null && \
167-
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark && \
168-
find /usr/local -type f -executable -exec ldd '{}' ';' 2>/dev/null \
169-
| awk '/=>/ { print $(NF-1) }' \
170-
| sort -u \
171-
| xargs -r dpkg-query --search 2>/dev/null \
172-
| cut -d: -f1 \
173-
| sort -u \
174-
| xargs -r apt-mark manual && \
175-
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
176-
177-
# 第六阶段: PECL配置和验证
178-
RUN set -eux && \
179-
pecl update-channels && \
180-
rm -rf /tmp/pear ~/.pearrc && \
181-
php --version
182-
91+
RUN set -eux; \
92+
\
93+
savedAptMark="$(apt-mark showmanual)"; \
94+
apt-get update; \
95+
apt-get install -y --no-install-recommends \
96+
libargon2-dev \
97+
libcurl4-openssl-dev \
98+
libedit-dev \
99+
libsodium-dev \
100+
libsqlite3-dev \
101+
libssl-dev \
102+
libxml2-dev \
103+
zlib1g-dev \
104+
${PHP_EXTRA_BUILD_DEPS:-} \
105+
; \
106+
rm -rf /var/lib/apt/lists/*; \
107+
\
108+
export \
109+
CFLAGS="$PHP_CFLAGS" \
110+
CPPFLAGS="$PHP_CPPFLAGS" \
111+
LDFLAGS="$PHP_LDFLAGS" \
112+
; \
113+
docker-php-source extract; \
114+
cd /usr/src/php; \
115+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
116+
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
117+
# https://bugs.php.net/bug.php?id=74125
118+
if [ ! -d /usr/include/curl ]; then \
119+
ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \
120+
fi; \
121+
./configure \
122+
--build="$gnuArch" \
123+
--with-config-file-path="$PHP_INI_DIR" \
124+
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
125+
\
126+
# make sure invalid --configure-flags are fatal errors instead of just warnings
127+
--enable-option-checking=fatal \
128+
\
129+
# https://github.com/docker-library/php/issues/439
130+
--with-mhash \
131+
\
132+
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
133+
--enable-ftp \
134+
# --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)
135+
--enable-mbstring \
136+
# --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)
137+
--enable-mysqlnd \
138+
# https://wiki.php.net/rfc/argon2_password_hash (7.2+)
139+
--with-password-argon2 \
140+
# https://wiki.php.net/rfc/libsodium
141+
--with-sodium=shared \
142+
# always build against system sqlite3 (https://github.com/php/php-src/commit/6083a387a81dbbd66d6316a3a12a63f06d5f7109)
143+
--with-pdo-sqlite=/usr \
144+
--with-sqlite3=/usr \
145+
\
146+
--with-curl \
147+
--with-libedit \
148+
--with-openssl \
149+
--with-zlib \
150+
\
151+
# bundled pcre does not support JIT on s390x
152+
# https://manpages.debian.org/stretch/libpcre3-dev/pcrejit.3.en.html#AVAILABILITY_OF_JIT_SUPPORT
153+
$(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \
154+
--with-libdir="lib/$debMultiarch" \
155+
\
156+
${PHP_EXTRA_CONFIGURE_ARGS:-} \
157+
; \
158+
make -j "$(nproc)"; \
159+
find -type f -name '*.a' -delete; \
160+
make install; \
161+
find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; \
162+
make clean; \
163+
\
164+
# https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable)
165+
cp -v php.ini-* "$PHP_INI_DIR/"; \
166+
\
167+
cd /; \
168+
docker-php-source delete; \
169+
\
170+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
171+
apt-mark auto '.*' > /dev/null; \
172+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
173+
find /usr/local -type f -executable -exec ldd '{}' ';' \
174+
| awk '/=>/ { print $(NF-1) }' \
175+
| sort -u \
176+
| xargs -r dpkg-query --search \
177+
| cut -d: -f1 \
178+
| sort -u \
179+
| xargs -r apt-mark manual \
180+
; \
181+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
182+
\
183+
# update pecl channel definitions https://github.com/docker-library/php/issues/443
184+
pecl update-channels; \
185+
rm -rf /tmp/pear ~/.pearrc; \
186+
# smoke test
187+
php --version
183188

184189
#COPY docker-php-ext-* docker-php-entrypoint /usr/local/bin/
185190

0 commit comments

Comments
 (0)