This wp-cli command executes fine from the command line, but not when run as a cron job.

/var/sites/d/mydomain/wp-cli --user=admin --url=https://mydomain/wordpress --path=/var/sites/d/mydomain/public_html/wordpress/ civicrm api job.execute auth=0

Any idea where I could start to diagnose this? I have checked the Civi logs in ConfigAndLog, nothing there. I have set php.ini as below

log_errors = On
log_errors_max_len = 1024
error_log = /var/sites/d/mydomain/logs/php_error.log

But nothing in that log either.

  • When you run it manually, is that the same user that cron is running as? Does cron send you an email with the output? You could try redirecting stdout & stderr to a file instead and see what that shows. – Aidan Nov 22 '18 at 9:22
  • Many thanks for the suggestions Aidan, will check that out and revert back... – Andy Nov 23 '18 at 8:44
  • Have redirected the output from the cron and am getting: "Fatal error: Class 'Phar' not found in /var/sites/d/mydomain/wp on line 3"?? Will ask my hosting for some support. – Andy Nov 23 '18 at 9:36
  • @Aidan fwiw, for some reason the version of PHP being called from the SSH command was 7.0 but from the Cron job 5.4. When I call 7.0 explcitly it works fine. Thank you for helping me get this resolved :) – Andy Nov 23 '18 at 10:20
  • Multiple versions of php are useful but a nasty trap at the same time! Glad you've got it sorted. Could you create this as an answer here? Say what you did to get the error and then how you resolved it - how did you change the version of php used from cron? That helps others who encounter a similar issue. – Aidan Nov 23 '18 at 16:22

To analyse this, as suggested by @Aidan I redirected the cron output to a file by adding this string to the end of the cron command:

&> /var/sites/d/mydomain/logs/cron.log

This showed that the command was failing with "Fatal error: Class 'Phar' not found in /var/sites/d/mydomain/wp on line 3"

Having queried this with my hosting support, it turned out that the implicit version of PHP called from cron was 5.4, but from SSH terminal, it defaulted to 7.0. Once I explicity called v7.0 php at the front of the cron command as below, it ran fine:

/usr/bin/php-7.0 /var/sites/d/mydomain/wp etc
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.