Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
🔧 Fixes WordPress upload directories permissions being set to root, use it with crontab.
#!/bin/bash
# Set this to your server's owner user (normally www-data)
user="www-data:www-data"
# Set this to the path to your wp-content
wp_content_path="/var/www/html/wp-content"
# Gets current year and month numbers
year=`date +%Y`
month=`date +%m`
# Creates the directories
mkdir "$wp_content_path/uploads"
mkdir "$wp_content_path/uploads/$year"
mkdir "$wp_content_path/uploads/$year/$month"
# Updates both the uploads, current year and current month directories
chown $user "$wp_content_path/uploads"
chown $user "$wp_content_path/uploads/$year"
chown $user "$wp_content_path/uploads/$year/$month"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment