As long as you don’t need root permissions in your PHP application / script, it is recommended to set up cron jobs with a web server specific user.
1. Find the apache user
Get the current apache user from the process status.
1 2 3 |
$ ps axo user,group,comm | egrep '(apache|httpd)' root root apache2 www-data www-data apache2 |
2. Edit the tab
Edit the crontab with the option -u and the specific apache user. This command will create a user-specific cron file in /var/spool/cron/crontabs/.
1 |
$ crontab -u www-data -e |
Set up your crontab and save the changes with CTRL-O.
1 2 3 4 5 6 7 8 |
# For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command */5 * * * * /bin/sh /var/www/magento/cron.sh |
3. Check the syslog file
After that, check the syslog file to make sure that the cronjob is running correctly.
1 |
$ grep 'CRON'.*\(www-data\) /var/log/syslog |