1

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) 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?

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!

| improve this answer | |
  • 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! – Demerit May 1 at 19:10
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

| improve this answer | |
  • 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? – David Hyman Apr 29 at 21:39
  • 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. – Demerit Apr 29 at 21:42

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.