#!/bin/bash # Automatically sets appropriate permissions on WordPress files # ===== Expects multiple sites stored under /var/www/{sitename}/html if [[ $* == *--all* ]]; then echo "Reset permissions for all WordPress sites? (Y/n)" read accept find /var/www -name 'wp-config.php' -exec dirname {} \; > ~/wp_list.txt else if [ -z $1 ]; then echo "Please enter a domain name." exit fi pub_html="/var/www/${1}/html" echo "Does this look correct? ${pub_html} (Y/n)" read accept echo ${pub_html} > ~/wp_list.txt fi if [ $accept == 'Y' ]; then while read pub_html; do sudo chown -R www-data:www-data ${pub_html} sudo find ${pub_html} -type f -exec chmod 644 {} + sudo find ${pub_html} -type d -exec chmod 755 {} + sudo find ${pub_html} -type d -exec chmod g+s {} \; sudo chmod g+w ${pub_html}/wp-content/ sudo chmod -R g+w ${pub_html}/wp-content/themes sudo chmod -R g+w ${pub_html}/wp-content/plugins if [ -d "${pub_html}/wp-content/cache" ]; then sudo chmod -R g+w ${pub_html}/wp-content/cache fi if [ -d "${pub_html}/wp-content/upgrade" ]; then sudo chmod -R g+w ${pub_html}/wp-content/upgrade fi if [ -d "${pub_html}/wp-content/db-backups" ]; then sudo chmod -R g+w ${pub_html}/db-backups fi if [ -d "${pub_html}/wp-content/wflogs" ]; then sudo chmod -R g+w ${pub_html}/wp-content/wflogs fi if [ -f "${pub_html}/wp-content/wp-cache-config.php" ]; then sudo chmod g+w ${pub_html}/wp-content/wp-cache-config.php fi echo "Permissions reset for ${pub_html}" done < ~/wp_list.txt fi rm ~/wp_list.txt