Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My LAMP is setup to work as user:www-data and all files and folders are created with that permissions.

I have setup for crontab as user@ubuntu.

So i do crontab -e and use this command:

*/5 * * * * php /var/www/public/voto_m/artisan top >/dev/null 2>&1

Basically that command just creates cache file in specified place (no problems with that), but that cache file is created with user:user permissions not user:www-data permissions.

How can i make that it will by default create file with user:www-data permissions?
I can't go and chown each time file is recreated.


share|improve this question
up vote 19 down vote accepted

You can write your entry into the system crontab /etc/crontab, which takes an additional argument specifying the user to run as (usually root, but can be www-data).

Your line would become:

*/5 * * * * www-data php /var/www/public/voto_m/artisan top >/dev/null 2>&1

Or you can edit the crontab of user www-data with su:

sudo su -c "crontab -e" www-data
share|improve this answer
actually second option doesn't work on most versions of Ubuntu – IRus Apr 1 '15 at 6:47
The second option does work for me on 12.04LTS. Maybe it doen't on later versions? – mivk May 10 '15 at 13:31
second option is not working on 14.04 – dgoosens Jul 28 '15 at 21:41

You can also run crontab with the -u argument to edit a crontab for a specific user:

sudo crontab -u www-data -e
share|improve this answer
this works on 14.04 – dgoosens Jul 28 '15 at 21:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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