Answers.Body: <p>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:</p>
  
  <pre><code>&amp;&gt; /var/sites/d/mydomain/logs/cron.log
  </code></pre>
  
  <p>This showed that the command was failing with "Fatal error: Class 'Phar' not found in /var/sites/d/mydomain/wp on line 3"</p>
  
  <p>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:</p>
  
  <pre><code>/usr/bin/php-7.0 /var/sites/d/mydomain/wp etc
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-24T18:31:26.857Z
Answers.LastActivityDate: 2018-11-24T18:31:26.857Z
Answers.UserDisplayName: Andy
Body: <p>This wp-cli command executes fine from the command line, but not when run as a cron job.  </p>
  
  <pre><code>/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
  </code></pre>
  
  <p>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</p>
  
  <pre><code>log_errors = On
  log_errors_max_len = 1024
  error_log = /var/sites/d/mydomain/logs/php_error.log
  </code></pre>
  
  <p>But nothing in that log either.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-22T09:22:20.660Z
Comments.Text: 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.
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-23T08:44:10.167Z
Comments.Text: Many thanks for the suggestions Aidan, will check that out and revert back...
Comments.UserDisplayName: Andy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-23T09:36:12.783Z
Comments.Text: 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.
Comments.UserDisplayName: Andy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-23T10:20:35.670Z
Comments.Text: @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 :)
Comments.UserDisplayName: Andy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-23T16:22:14.770Z
Comments.Text: 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.
Comments.UserDisplayName: Aidan
Tags: <scheduled-job>
Title: Scheduled Job not executing with wp-cli under cron, but works manually
ThreadText: # Scheduled Job not executing with wp-cli under cron, but works manually
  
  (Asked by: username_0 on 2018-11-21)
  
  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.
  
  **Tags:** scheduled-job
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: Many thanks for the suggestions username_1, will check that out and revert back...  
  > **username_0**: 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.  
  > **username_0**: @username_1 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 :)  
  > **username_1**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-11-24. Score: 2
  
  To analyse this, as suggested by @username_1 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
  
  ```
  
  
  ---
  
  