Skip to content

Instantly share code, notes, and snippets.

@richardevcom
Last active January 21, 2025 12:37
Show Gist options
  • Save richardevcom/7a98f152bc240fdfc8959d83ac239b4c to your computer and use it in GitHub Desktop.
Save richardevcom/7a98f152bc240fdfc8959d83ac239b4c to your computer and use it in GitHub Desktop.
Fix & secure WordPress files & permissions
chown -R www-data:www-data .
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
#find . -type f -name ".htaccess" chmod 640 {} \; # If you're not using Pretty URLs (permalinks), use 604 < 640 permissions.
find . -type f -name "wp-config.php" chmod 440 {} \;
@richardevcom
Copy link
Author

WordPress official post Changing File Permissions suggests securing wp-config.php with 440 permission and .htaccess between 604 < 644 permission.

If you're using Pretty Permalinks (URLs), it is suggested to use 666 😈 permission.

@richardevcom
Copy link
Author

[UPDATE]
If you're using plugin that rewrites .htaccess or wp-config.php files (for example, LiteSpeed Cache), you should leave at least 6** permissions, otherwise you'll have to update these files manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment