Skip to content

Instantly share code, notes, and snippets.

@che-wf
Forked from Adirael/fix-wordpress-permissions.sh
Last active February 8, 2017 20:08
Show Gist options
  • Save che-wf/f54846c18ebe313343749d8b3e9576e2 to your computer and use it in GitHub Desktop.
Save che-wf/f54846c18ebe313343749d8b3e9576e2 to your computer and use it in GitHub Desktop.
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
WS_GROUP=www-data # <-- webserver group
# reset to safe defaults
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 755 {} \;
find ${WP_ROOT} -type f -exec chmod 644 {} \;
# allow wordpress to manage wp-config.php (but prevent world access)
chgrp ${WS_GROUP} ${WP_ROOT}/wp-config.php
chmod 660 ${WP_ROOT}/wp-config.php
# allow wordpress to manage wp-content
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 664 {} \;
@che-wf
Copy link
Author

che-wf commented Feb 8, 2017

For those who don't know, here are the steps to run this. I'm referring to Ubuntu, so you may need to change some of these steps to match your operating system.

  1. Put this file on your system where you can run it from and go to that folder in your terminal.
  2. Make it executable using command line chmod +x / fix-wordpress-permissions.sh.
  3. Run it with your WordPress installation folder as a parameter like this sh ./fix-wordpress-permissions.sh /home/www/wordpress.

That's it!

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