How to run crontab as www-data user in Linux?

By Hardik Savani November 5, 2023 Category : Ubuntu

In this example, I will show you how to run crontab as www-data in ubuntu. you can see cron job run as www-data. This article goes in detail on run cron job as non root user. if you want to see an example of how to run crontab as another user then you are the right place.

A few days ago, I was working on my php laravel project and I need to set up cronjob on my ubuntu server. i setup cron job currently and it is working fine. but I had a permission issue. cron job was running as root user and storage folder has www-data permission. so i was giving me permission error, some folder has root user and some folder has www-data user permission.

However, I search on google and find out the way how to resolve it. you can set up a cron job using the following crontab command, so it will run as a www-data user. you can set up another user if you want.

Let's see bellow solution command:

Solution Command:

sudo crontab -u www-data -e

Then you can setup your command like you can add laravel cron command to that file.

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Then you will find proper permission for your storage folder as bellow:

I hope it can help you...

Tags :
Shares