5

This is a weird one.

Wordpress by default stores uploaded media in monthly sub-directories of the uploads directory. Eg wp-content/uploads/2016/07/

On one of my sites, this directory's owner gets set to "root:root", which means that nothing can be uploaded to the directory via the web server.

Any ideas what might cause this behaviour? I can imagine a cron script creating this behaviour, but I don't see how Wordpress itself should be able to create a directory owned by root.

4
  • Are you running your own web server? If Apache httpd, you probably didnt set the User and Group directives.
    – user42826
    Jul 5, 2016 at 16:57
  • 1
    you most likely have some different process that access and change the permissions of the directories. Jul 5, 2016 at 17:21
  • This sounds like a server issue and not a wordpress issue. Have you looked on server vault?
    – user9447
    Jul 5, 2016 at 18:13
  • Try to modify your permalinks structure if wp doesn't have permissions to write to your server it would bring up an error, and even if you can modify your .htaccess file via the permalink option menu, that doesn't mean you shouldn't check further permissions. Just disincluding eventual issue.
    – knif3r
    Jul 5, 2016 at 19:26

2 Answers 2

9

I've had the same problem, and in my case it was the Wordpress cronjob. I was calling the wp-cron.php as a root cron job, and this script also generates the monthly upload folder.

If you call wp-cron.php via cronjob you need to do this as the web server user (or i.e. in Plesk the site user and group psacln). The owner of the created monthly folder is always the user the wp-cron.php is called from.

5
  • Thank you man! I moved wp cronjobs to crontab and it was causing this. Jul 2, 2020 at 15:23
  • 1
    How do I change the crontab to execute the process as a different user?
    – jjxtra
    Jul 4, 2022 at 18:04
  • 1
    @jjxtra. You need to create/edit the crontab for the user that your server runs under. Eg, on Ubuntu Linux it is 'www-data'. You can do this by running sudo crontab -e -u www-data.
    – fred2
    Jul 26, 2022 at 14:38
  • Awesome, thanks!
    – jjxtra
    Jul 26, 2022 at 15:25
  • This looks like the fix I have been searching for! Makes complete sense. Have moved all the cron jobs for my website into the -u wp-user crontab, will see what happens on the first of next month
    – itsricky
    Mar 9, 2023 at 0:10
1

I had the same problem, also a cronjob, but WP CLI was the issue. The cronjob was running a 'wp plugin' command every month, the 'wp plugin' command was creating the monthly folder owned by the same user that ran the cronjob -- root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.