setup cron using php -f (or g)


I thought I would post over setting up a cron path, so users find it easier as follows:
php -f /chroot/home/siteworx-name/yourdomain.url/html/path/to/cron.php
(you do not have to use /chroot, and some may not have /chroot, so maybe better to use /home/siteworx-name/yourdomain.url/html/path/to/cron.php)
so, if you need to setup a cron, and shown /usr/bin/php -f, please use above
I hope that helps a little
Many thanks

Hey John,

can I pick your brain a little more? if I want to log the ouput of each and every cron-job run, I usually add >> logfile.log 2>&1
But php -f /chroot/home/siteworx-name/yourdomain.url/html/path/to/cron.php >> /var/log/logfile.txt 2>&1
or php -f /chroot/home/siteworx-name/yourdomain.url/html/path/to/cron.php >> /chroot/home/siteworx-name/yourdomain.url/html/path/to/logfile.txt 2>&1
don’t work for me. Any ideas why?

And does anyone know/have a list of cron parameters (-f -g -q etc.) ? Google finds millions of hits but no answers


Oh and to make things perfect, I would love to have timestamps too :wink:

I am unsucessfully fiddling with my cron command and added ‘date +20%y%m%d_%H%M%S’ like this

php -f /chroot/home/siteworx-name/yourdomain.url/html/path/to/cron.php ‘date +20%y%m%d_%H%M%S’ >> /chroot/home/siteworx-name/yourdomain.url/html/path/to/logfile.txt 2>&1

but since nothing is logged I can’t see, if that works.

Hi Michael
I hope your well and it’s cooled down a little for you
Good question
You can use the following, which will give you a log file output, but change as needed.
For testing, I used whmcs cron
I think your issue maybe that you are trying to save into a folder which the perms are wrong, and the folder needs to be siteworx:siteworx, or better still, place outside of hosting root, and set siteworx:siteworx 766 or 777
I hope that helps a little
Many thanks
php -q /home/unix-name/whmcs_crons/cron.php > /home/unix-name/master.url/html/log/date +\%Y\%m\%d\%H\%M\%S-testcron.log 2>&1
file saved 20170711185401-testcron.log

Hi John,

Thanks! But why -q and not -f here?
And I was looking for a way to add the timestamp to each line of the log file, thus the >>
Do you happen to know that too?

Hi Michael

Sorry I am not sure, -q was advised by whmcs cron. I know -f is for file parsing in php code

To be honest, for inline cron actions, I am not sure if this is possible as the cron runs at a set time, therefore the actions are run at that time

I’ll have to have a think though, as I’m just in the dentist waiting room and have a few minutes free

Many thanks