Skip to content

Instantly share code, notes, and snippets.

@orvn
Created December 23, 2020 04:44
Show Gist options
  • Save orvn/f8f35d33768c064cc5b07a429ee48b14 to your computer and use it in GitHub Desktop.
Save orvn/f8f35d33768c064cc5b07a429ee48b14 to your computer and use it in GitHub Desktop.
Correctly repair Wordpress permissions (Redhat, CentOS, Debian, Ubuntu, MacOS, etc.)
#!/bin/bash
#
# run with:
# ./wp_perms.sh {path}
#
OWNER=apache # Wordpress owner, or the user that runs php. On CentOS/Redhat this is usually apache. On Ubuntu/Debian, this could be www-data
GROUP=apache # Configure your own group, or use the group from the user above (apache, www-data, etc.)
ROOT=$1 # Specify path when invoking this script
# Reset permissions to defaults
find ${ROOT} -exec chown ${OWNER}:${GROUP} {} \;
find ${ROOT} -type d -exec chmod 755 {} \;
find ${ROOT} -type f -exec chmod 644 {} \;
# Make wp-config non-public
chgrp ${GROUP} ${ROOT}/wp-config.php
chmod 660 ${ROOT}/wp-config.php
# Give Wordpress the permissions it needs
find ${ROOT}/wp-content -exec chgrp ${GROUP} {} \;
find ${ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${ROOT}/wp-content -type f -exec chmod 664 {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment