Crontab file PHP doesn’t work but the command line then working

Hi everybody.
I’m using Hestiacp with ubuntu version 20.4 and install multiple versions php
I created one crontab run file auto.php
I have tried all of the following methods but they don’t work (I restarted the crontab service after each method)
===Methods 1:===
#crontab -e
add: */5 * * * * /usr/bin/php /home/admin/web/
or add: */5 * * * * root /usr/bin/php /home/admin/web/
===Methods 2:===

  • the command line
    #v-add-cron-job admin ‘/5’ '’ ‘’ '’ ‘*’ ‘sudo /usr/bin/php /home/admin/web/’

===Methods 3:===

But when I run the command line on my server:
#php /usr/bin/php /home/admin/web/

it executes and everything is as it should be but it doesn’t work from crontab

Please help me!
Thanks a lot!

You can’t use sudo for /usr/bin/php with the admin user

/usr/bin/php /home/admin/web/

Should work fine or

Create an crontab as the root user crontab -e -u root

@eris Thank you for responding!
In method 3: I don’t use “sudo” as picture but it still won’t execute
with “crontab -e -u root” I’ve used in method 1 because I’m logged in as root do not execute

Try adding it to a log file so you can see whats happening when it tries to run:

/usr/bin/php /home/admin/web/ > /home/admin/web/

Or something like that :slight_smile: I’ve had it before where the PHP version running under cron is different to what was running on the site, and it gave syntax errors

1 Like

In that case you might want to use /usr/bin/phpx.x

1 Like