Skip to content

Commit 5af0b0c

Browse files
committed
Adjust user:group values for FPM and non-root usage (which doesn't use the APACHE_RUN_* environment variables)
1 parent 6f6ea03 commit 5af0b0c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

docker-entrypoint.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ file_env() {
2424
}
2525

2626
if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
27-
: "${APACHE_RUN_USER:-www-data}"
28-
: "${APACHE_RUN_GROUP:-www-data}"
29-
export APACHE_RUN_USER APACHE_RUN_GROUP
27+
if [ "$(id -u)" = '0' ]; then
28+
case "$1" in
29+
apache2*)
30+
user="${APACHE_RUN_USER:-www-data}"
31+
group="${APACHE_RUN_GROUP:-www-data}"
32+
;;
33+
*) # php-fpm
34+
user='www-data'
35+
group='www-data'
36+
;;
37+
esac
38+
else
39+
user="$(id -u)"
40+
group="$(id -g)"
41+
fi
3042

3143
if ! [ -e index.php -a -e wp-includes/version.php ]; then
3244
echo >&2 "WordPress not found in $PWD - copying now..."
@@ -38,7 +50,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
3850
--file - \
3951
--one-file-system \
4052
--directory /usr/src/wordpress \
41-
--owner "${APACHE_RUN_USER}" --group "${APACHE_RUN_GROUP}" \
53+
--owner "$user" --group "$group" \
4254
. | tar --extract --file -
4355
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
4456
if [ ! -e .htaccess ]; then
@@ -55,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5567
</IfModule>
5668
# END WordPress
5769
EOF
58-
chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} .htaccess
70+
chown "$user:$group" .htaccess
5971
fi
6072
fi
6173

@@ -124,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT
124136
}
125137
126138
EOPHP
127-
chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} wp-config.php
139+
chown "$user:$group" wp-config.php
128140
fi
129141

130142
# see http://stackoverflow.com/a/2705678/433558

0 commit comments

Comments
 (0)