Skip to content

Instantly share code, notes, and snippets.

@matpratta
Last active April 1, 2020 21:15
Show Gist options
  • Save matpratta/5a4120c20c11954fcdb99475c43ddedd to your computer and use it in GitHub Desktop.
Save matpratta/5a4120c20c11954fcdb99475c43ddedd to your computer and use it in GitHub Desktop.
πŸ”§ 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