Skip to content

Instantly share code, notes, and snippets.

@sebastian13
Last active April 7, 2024 16:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastian13/c57fb8f62863112825b7b1b912b9a2d8 to your computer and use it in GitHub Desktop.
Save sebastian13/c57fb8f62863112825b7b1b912b9a2d8 to your computer and use it in GitHub Desktop.
Set WordPress' file permissions when using docker compose
#!/bin/bash
# https://gist.github.com/sebastian13/c57fb8f62863112825b7b1b912b9a2d8
#
# This script sets WordPress' file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
# and https://stackoverflow.com/a/23755604/8940679
#
# Idea from https://github.com/mconigliaro/notes/blob/master/wordpress/permissions.md
#
# To use this script run:
# ./fix-wordpress-permissions.sh [CONTAINER]
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_CONTAINER=${1:-'wordpress'} # <-- container running wordpress
docker compose exec ${WP_CONTAINER} /bin/bash -c " \
chown --recursive --changes ${WP_OWNER}:${WP_GROUP} wp-content && \
find wp-content -printf '' && \
find wp-content -type f ! -perm 644 -print0 | xargs --no-run-if-empty --null chmod --changes 644 && \
find wp-content -type d ! -perm 755 -print0 | xargs --no-run-if-empty --null chmod --changes 755 \
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment