Skip to content

Commit

Permalink
Adjust user:group values for FPM and non-root usage (which doesn't us…
Browse files Browse the repository at this point in the history
…e the APACHE_RUN_* environment variables)
  • Loading branch information
tianon committed Dec 21, 2017
1 parent 6f6ea03 commit 5af0b0c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ file_env() {
}

if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
: "${APACHE_RUN_USER:-www-data}"
: "${APACHE_RUN_GROUP:-www-data}"
export APACHE_RUN_USER APACHE_RUN_GROUP
if [ "$(id -u)" = '0' ]; then
case "$1" in
apache2*)
user="${APACHE_RUN_USER:-www-data}"
group="${APACHE_RUN_GROUP:-www-data}"
;;
*) # php-fpm
user='www-data'
group='www-data'
;;
esac
else
user="$(id -u)"
group="$(id -g)"
fi

if ! [ -e index.php -a -e wp-includes/version.php ]; then
echo >&2 "WordPress not found in $PWD - copying now..."
Expand All @@ -38,7 +50,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
--file - \
--one-file-system \
--directory /usr/src/wordpress \
--owner "${APACHE_RUN_USER}" --group "${APACHE_RUN_GROUP}" \
--owner "$user" --group "$group" \
. | tar --extract --file -
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
if [ ! -e .htaccess ]; then
Expand All @@ -55,7 +67,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
</IfModule>
# END WordPress
EOF
chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} .htaccess
chown "$user:$group" .htaccess
fi
fi

Expand Down Expand Up @@ -124,7 +136,7 @@ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROT
}
EOPHP
chown ${APACHE_RUN_USER}:${APACHE_RUN_GROUP} wp-config.php
chown "$user:$group" wp-config.php
fi

# see http://stackoverflow.com/a/2705678/433558
Expand Down

0 comments on commit 5af0b0c

Please sign in to comment.