Run cron jobs by apache

Issues related to applications and software problems
Post Reply
GioMBG
Posts: 59
Joined: 2012/02/27 00:28:14
Location: Conthey Suisse
Contact:

Run cron jobs by apache

Post by GioMBG » 2019/03/14 18:13:39

Hi All,
ususally I always run cron jobs by root but at this stage I would like run cron jobs by apache to be able to overwrite logs file generated by cron that, when runned by root, it is impossible to overwrite by apache.
I see around that "maybe" is possible put the user before the cron job after the time es :

Code: Select all

* * * * * apache /usr/bin/php /var/www/html/admin/cron/worldwide_music_records/cron_igniter.php
any suggestions ?

also I would like to know if there can be issues when run cron not by root
thx

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Run cron jobs by apache

Post by TrevorH » 2019/03/14 18:17:30

There are several cron formats. The one where you specify the user is the system crontab under /etc. You would be better using the crontab -r -u apache command to edit the apache user's user crontab. That doesn't take a user parameter as it already runs as the user the crontab belongs to.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: Run cron jobs by apache

Post by MartinR » 2019/03/14 18:28:01

The easiest way is to use crontab -e -u apache when logged in as apache. This will set up the per-user crontab and you don't then need the username field (see crontab(5)). If you specifically want to use either /etc/crontab or a file in /etc/cron.d then you will need the username as you show.

Post Reply