Skip to content

Commit d3f846a

Browse files
committed
Run php container as www-data
1 parent bb8709d commit d3f846a

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

services/php/Dockerfile

+18-20
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@ ARG PHP_EXTENSIONS
66
ARG CONTAINER_PACKAGE_URL
77

88

9-
COPY --from=composer /usr/bin/composer /usr/bin/composer
10-
COPY ./extensions /tmp/extensions
11-
WORKDIR /tmp/extensions
12-
13-
# php alpine image's www-data user uid & gid are 82, change them to 1000 (primary user)
14-
RUN apk add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data
15-
16-
RUN if [ "${CONTAINER_PACKAGE_URL}" != "" ]; then \
17-
sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories; \
18-
fi
19-
20-
21-
RUN if [ "${PHP_EXTENSIONS}" != "" ]; then \
22-
apk add --no-cache autoconf g++ libtool make curl-dev gettext-dev linux-headers; \
23-
fi
9+
RUN sed -i "s/dl-cdn.alpinelinux.org/${CONTAINER_PACKAGE_URL}/g" /etc/apk/repositories
2410

2511

26-
RUN chmod +x install.sh && sh install.sh && rm -rf /tmp/extensions
12+
COPY ./extensions /tmp/extensions
13+
WORKDIR /tmp/extensions
14+
RUN chmod +x install.sh \
15+
&& sh install.sh \
16+
&& rm -rf /tmp/extensions
2717

2818

2919
RUN apk --no-cache add tzdata \
@@ -35,9 +25,17 @@ RUN apk --no-cache add tzdata \
3525
RUN apk add gnu-libiconv --no-cache --repository http://${CONTAINER_PACKAGE_URL}/alpine/edge/community/ --allow-untrusted
3626
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
3727

38-
# Install Composer
39-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
40-
# Change Composer Home
41-
ENV COMPOSER_HOME="/tmp/composer"
28+
29+
# Install composer and change it's cache home
30+
RUN curl -o /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
31+
&& chmod +x /usr/bin/composer
32+
ENV COMPOSER_HOME=/tmp/composer
33+
34+
35+
# php image's www-data user uid & gid are 82, change them to 1000 (primary user)
36+
RUN apk --no-cache add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data
37+
# Use www-data to run the first process
38+
USER www-data
39+
4240

4341
WORKDIR /www

services/php/extensions/install.sh

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ echo "============================================"
1414
echo
1515

1616

17+
if [ "${PHP_EXTENSIONS}" != "" ]; then
18+
apk add --no-cache autoconf g++ libtool make curl-dev gettext-dev linux-headers
19+
fi
20+
21+
1722
export EXTENSIONS=",${PHP_EXTENSIONS},"
1823

1924

services/php/php-fpm.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
; Unix user/group of processes
2121
; Note: The user is mandatory. If the group is not set, the default user's group
2222
; will be used.
23-
user = www-data
24-
group = www-data
23+
;user = www-data
24+
;group = www-data
2525

2626
; The address on which to accept FastCGI requests.
2727
; Valid syntaxes are:

services/php54/Dockerfile

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@ ARG PHP_EXTENSIONS
66
ARG CONTAINER_PACKAGE_URL
77

88

9+
RUN sed -i "s/httpredir.debian.org/${CONTAINER_PACKAGE_URL}/g" /etc/apt/sources.list; \
10+
&& sed -i "s/security.debian.org/${CONTAINER_PACKAGE_URL}\/debian-security/g" /etc/apt/sources.list; \
11+
&& apt-get update
12+
13+
914
COPY ./extensions /tmp/extensions
1015
WORKDIR /tmp/extensions
11-
1216
RUN chmod +x install.sh \
1317
&& sh install.sh \
1418
&& rm -rf /tmp/extensions
1519

1620

17-
# Install Composer
18-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
19-
# Change Composer Home
20-
ENV COMPOSER_HOME="/tmp/composer"
21+
# Install composer and change it's cache home
22+
RUN curl -o /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
23+
&& chmod +x /usr/bin/composer
24+
ENV COMPOSER_HOME=/tmp/composer
25+
26+
27+
# php image's www-data user uid & gid are 82, change them to 1000 (primary user)
28+
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
29+
# Use www-data to run the first process
30+
USER "www-data"
2131

2232
WORKDIR /www

services/php54/extensions/install.sh

+4-16
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@ echo "============================================"
1212
echo
1313

1414

15-
if [ "${CONTAINER_PACKAGE_URL}" != "" ]; then
16-
sed -i "s/httpredir.debian.org/${CONTAINER_PACKAGE_URL}/g" /etc/apt/sources.list
17-
sed -i "s/security.debian.org/${CONTAINER_PACKAGE_URL}\/debian-security/g" /etc/apt/sources.list
18-
fi
19-
20-
21-
if [ "${PHP_EXTENSIONS}" != "" ]; then
22-
echo "---------- Update source list ----------"
23-
apt-get update
24-
fi
15+
echo "---------- Install zip extension ----------"
16+
apt-get install -y zlib1g-dev unzip
17+
docker-php-ext-install zip
2518

2619

2720
export EXTENSIONS=",${PHP_EXTENSIONS},"
@@ -50,11 +43,6 @@ if [ -z "${EXTENSIONS##*,bz2,*}" ]; then
5043
docker-php-ext-install bz2
5144
fi
5245

53-
if [ -z "${EXTENSIONS##*,zip,*}" ]; then
54-
echo "---------- Install zip ----------"
55-
docker-php-ext-install zip
56-
fi
57-
5846
if [ -z "${EXTENSIONS##*,pcntl,*}" ]; then
5947
echo "---------- Install pcntl ----------"
6048
docker-php-ext-install pcntl
@@ -265,7 +253,7 @@ fi
265253

266254
if [ -z "${EXTENSIONS##*,memcached,*}" ]; then
267255
echo "---------- Install memcached ----------"
268-
apt-get install -y libmemcached-dev zlib1g-dev
256+
apt-get install -y libmemcached-dev
269257
pecl install memcached-2.2.0
270258
docker-php-ext-enable memcached
271259
fi

services/php54/php-fpm.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
; Unix user/group of processes
2121
; Note: The user is mandatory. If the group is not set, the default user's group
2222
; will be used.
23-
user = www-data
24-
group = www-data
23+
;user = www-data
24+
;group = www-data
2525

2626
; The address on which to accept FastCGI requests.
2727
; Valid syntaxes are:

0 commit comments

Comments
 (0)