Setup Crontab to run WP Cron

Is there a way to setup a crontab task to run? I’d like to kick off my WP cron jobs automatically every minute without having to run them myself or visiting the site.

To do this you would have to disable WP-Cron and use the server’s cron setting up a crontab to run every minute. There are loads of examples for doing this on the web. My personal preference is to run the task via WP-CLI in the crontab.

What I’m looking for is how to manage/edit Crontab within the Local by Flywheel instance.

Hi Justin,

To setup cron[tab] in a Local site container, you’ll need to:

  1. Right-click on the site in Local’s sidebar and go to “Open Site SSH”
  2. Install cron by running apt-get update && apt-get install cron
  3. Run crontab -e to edit the cron schedule

From there, you can follow the instructions of a tutorial such as https://easyengine.io/tutorials/wordpress/wp-cron-crontab/

2 Likes

Thanks, @clay! As a follow-up, here is my crontab call:
*/1 * * * * /usr/local/bin/wp cron event run --due-now --path=/app/public/ --allow-root > /app/public/wp-content/cron.log 2>&1

However, I’m getting the following error in my log:
/usr/bin/env: php: No such file or directory

If I change it to:
*/1 * * * * cd /app/public; php /app/public/wp-cron.php?doing_wp_cron > /app/public/wp-content/cron.log 2>&1

I get:
/bin/sh: 1: php: not found

And finally, if I use:
*/1 * * * * curl http://XXXX.ngrok.io/wp-cron.php?doing_wp_cron > /app/public/wp-content/cront.log 2>&1

I get:
/bin/sh: 1: curl: not found

I’d prefer to use the first call, using wp cli, but not being a sys admin, not sure what the error means or how to fix.

Figured it out. I added the PATH to the top of the crontab:

PATH=/bin:/usr/bin:/usr/local/bin

*/1 * * * * wp cron event run --due-now --path=/app/public/ --allow-root > /app/public/wp-content/cron.log 2>&1
2 Likes

Great, you solved the problem.
If WordPress users have no experience with setting up cron jobs on servers, you can do it with WP Cron plugin:
https://wordpress.org/plugins/easycron/.