WordPress – How to Fix File and Folder Permissions – reset_wp_perm.sh

#!/bin/bash
#RyS20140530
echo "v1.1, 2014120301"
echo ""
echo "Current directory is:"
pwd
read -p "Make sure you are in your WordPress directory, are you ? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo ""
echo "... Setting chmod 775 for all directories"
find ./ -type d -exec chmod 775 {} \;
echo "... Setting chmod 664 for all files"
find ./ -type f -exec chmod 664 {} \;
echo "... But setting chmod 664 for wp-config.php, though, assuming chown is set to ft
p user"
chmod 664 wp-config.php
echo "Type username"
read user
echo "... Setting chown $user:www-data for *"
chown -R $user:www-data *
#echo "... Setting chown to :www-data for wp-content/uploads"
#chown -R :www-data wp-content/uploads
echo "... Setting chown :www-data for .htaccess"
chown :www-data .htaccess
echo "... Setting chmod 644 for .htaccess"
chmod 644 .htaccess
echo ""
echo "Done"
echo ""
read -p "Also run fix for WordPress upgrade and file permissions issue ? (y/n) " -n 1
-r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo ""
echo "... Changing wp-content group ownership to www-data"
chgrp -R www-data wp-content
echo "... Making wp-content and all of its sub-directories group-writable"
chmod -R g+w wp-content
echo "... Newly-created files to be group-owned"
chmod g+s wp-content
echo "If necessary, add the following to the bottom of wp-config.php"
##/* Force direct file updating
##- taken from http://www.charleshooper.net/blog/wordpress-auto-upgrade-and-dumb-permi
ssions/
##For more information, take a look at wp-admin/includes/file.php’s function get_files
ystem_method
##*/
echo "define('FS_METHOD', 'direct');"
fi
fi

Sources:
https://codex.wordpress.org/Changing_File_Permissions
http://www.charleshooper.net/blog/wordpress-auto-upgrade-and-dumb-permissions/

Leave a Reply