Answers.Body: <p>Well, I seem to have resolved it by replacing cli.php with cron.php in the command line.  Of course it didn't do anything when I ran the command from the terminal, but I plugged it into the cron jobs list and it seems to be executing the jobs now.  I am just lucky I spotted the "cron.php" file in the bin folder, and took a chance on it being what I needed.  </p>
  
  <p>My sympathies to any novice like me who has to set up Cron Jobs for CiviCRM -- the instructions may make sense to a Linux expert or php programmer, but to complete this simple and essential task, it has taken me months.  </p>
  
  <p>Thanks for your help, folks!    </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-01T19:10:57.863Z
Answers.Text: Ok if it's working great just now it sounds like you're simulating a web request from the command line, by running the fcgi binary against a script meant to be called from the web. See how it goes!
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-30T22:33:25.777Z
Answers.LastActivityDate: 2020-04-30T22:33:25.777Z
Answers.UserDisplayName: David Hyman
Answers.Body: <p>I think this is maybe the same as <a href="https://stackoverflow.com/questions/10886539/why-does-php-sapi-not-equal-cli-when-called-from-a-cron-job">https://stackoverflow.com/questions/10886539/why-does-php-sapi-not-equal-cli-when-called-from-a-cron-job</a></p>
  
  <p>The key line is <code>Do not always expect /usr/bin/php to be a link to php-cli binary</code>.</p>
  
  <p>Meaning: In your cron command give the full path to the exact version of the php binary that you want, which might be something like <code>/usr/bin/php-cli</code>. I'm not familiar with InmotionDirect, but they probably have <code>php</code> linked to <code>cgi-fcgi</code>, so you need to find the right full path to the cli version of php. I'm sure InmotionDirect can tell you. Possibly this: <a href="https://www.inmotionhosting.com/support/questions/communities/1/topics/10968-using-cli-version-of-php-with-cron" rel="nofollow noreferrer">https://www.inmotionhosting.com/support/questions/communities/1/topics/10968-using-cli-version-of-php-with-cron</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-29T21:39:40.583Z
Answers.Text: Well, as I said, my command is:
  php public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s [site]-u [user] -p [password] -e Job -a execute
  
  I have verified that, at least when run from the terminal, this works, so I guess this is the right path to the cli.php.  But maybe "cli.php" is not what I should be running at all (since the cli means command line interface).  If I am searching in my files on the server for an equivalent binary that will run from a cron job, would it be called cron.php?  Would it take the same parameters, etc?
Answers.UserDisplayName: David Hyman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-29T21:42:50.350Z
Answers.Text: When run from the terminal your PATH or a wrapper might be different than from cpanel cron. Based on the article on the hosting company's site I would change php to php-cli in your cron command, the php at the start of the line.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-29T02:36:37.677Z
Answers.LastActivityDate: 2020-04-29T02:36:37.677Z
Answers.UserDisplayName: Demerit
Body: <p>Using WordPress 5.4 and CiviCRM Version 5.18.4.  Hosting with InmotionDirect, managing via Cpanel.</p>
  
  <p>Trying to follow the instructions to set up our cron job.  I got the command line to work, finally, as:
  php public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s [site] -u [user] -p [password] -e Job -a execute</p>
  
  <p>It worked, and I thought I was done.  Plugged it into the Crom job list in Cpanel and sat back.  </p>
  
  <p>Error via email: "cli.php can only be run from command line."  </p>
  
  <p>Well, nobody mentioned that in the instructions.  Is that a universal rule, or is just my hosting service being fussy?</p>
  
  <p>Based on an answer here (<a href="https://civicrm.stackexchange.com/questions/20620/setting-up-cron-jobs-on-cpanel">Setting up cron jobs on cPanel</a>) I tried putting the command line in a file and having the cron job command be just sh thatfile.  Same error.  </p>
  
  <p>Is there a workaround?  Or do I have to manually install yet another program like wp-cli just to run my jobs?  </p>
  
Tags: <wordpress><cron><cron-job>
Title: cli.php can only be run from command line
ThreadText: # cli.php can only be run from command line
  
  (Asked by: username_0 on 2020-04-29)
  
  Using WordPress 5.4 and CiviCRM Version 5.18.4. Hosting with InmotionDirect, managing via Cpanel.
  
  Trying to follow the instructions to set up our cron job. I got the command line to work, finally, as:
  php public\_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s [site] -u [user] -p [password] -e Job -a execute
  
  It worked, and I thought I was done. Plugged it into the Crom job list in Cpanel and sat back.
  
  Error via email: "cli.php can only be run from command line."
  
  Well, nobody mentioned that in the instructions. Is that a universal rule, or is just my hosting service being fussy?
  
  Based on an answer here ([Setting up cron jobs on cPanel](https://civicrm.stackexchange.com/questions/20620/setting-up-cron-jobs-on-cpanel)) I tried putting the command line in a file and having the cron job command be just sh thatfile. Same error.
  
  Is there a workaround? Or do I have to manually install yet another program like wp-cli just to run my jobs?
  
  **Tags:** wordpress, cron, cron-job
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-04-30. Score: 1
  
  Well, I seem to have resolved it by replacing cli.php with cron.php in the command line. Of course it didn't do anything when I ran the command from the terminal, but I plugged it into the cron jobs list and it seems to be executing the jobs now. I am just lucky I spotted the "cron.php" file in the bin folder, and took a chance on it being what I needed.
  
  My sympathies to any novice like me who has to set up Cron Jobs for CiviCRM -- the instructions may make sense to a Linux expert or php programmer, but to complete this simple and essential task, it has taken me months.
  
  Thanks for your help, folks!
  
  > **Comments:**
  > **username_1**: Ok if it's working great just now it sounds like you're simulating a web request from the command line, by running the fcgi binary against a script meant to be called from the web. See how it goes!  
  
  ---
  
  ### Answer by username_1 on 2020-04-29. Score: 0
  
  I think this is maybe the same as <https://stackoverflow.com/questions/10886539/why-does-php-sapi-not-equal-cli-when-called-from-a-cron-job>
  
  The key line is `Do not always expect /usr/bin/php to be a link to php-cli binary`.
  
  Meaning: In your cron command give the full path to the exact version of the php binary that you want, which might be something like `/usr/bin/php-cli`. I'm not familiar with InmotionDirect, but they probably have `php` linked to `cgi-fcgi`, so you need to find the right full path to the cli version of php. I'm sure InmotionDirect can tell you. Possibly this: <https://www.inmotionhosting.com/support/questions/communities/1/topics/10968-using-cli-version-of-php-with-cron>
  
  > **Comments:**
  > **username_0**: Well, as I said, my command is: php public_html/wp-content/plugins/civicrm/civicrm/bin/cli.php -s [site]-u [user] -p [password] -e Job -a execute  I have verified that, at least when run from the terminal, this works, so I guess this is the right path to the cli.php.  But maybe "cli.php" is not what I should be running at all (since the cli means command line interface).  If I am searching in my files on the server for an equivalent binary that will run from a cron job, would it be called cron.php?  Would it take the same parameters, etc?  
  > **username_1**: When run from the terminal your PATH or a wrapper might be different than from cpanel cron. Based on the article on the hosting company's site I would change php to php-cli in your cron command, the php at the start of the line.  
  
  ---
  
  