How To Create WP Cronjob From RunCloud Dashboard Using Wp-cli ?

Preview of creating cronjob from runcloud dashboard using wp-cli

How to create WordPress Cronjob from RunCloud dashboard using Wp-cli ?

Cronjobs are an essential tool for automating tasks in a Linux environment. They allow you to schedule commands to run automatically at specific intervals, freeing up your time and improving efficiency. In the world of WordPress, cronjobs can be used to perform a wide range of tasks, from scheduling backups to updating plugins.

As a community user, the most asked questions among RunCloud users may be regarding the running of a cronjob. Even though RunCloud managed to provide a simple UI the right method for adding cronjob is still a confusing part for most users. Please check out our youtube video if you require further assistance.



Introduction

Most users prefer disabling the default wp-cron and use the cronjob from the server end. I find it much more server resource-friendly as well. However, most of them run into the following error after setting their own cronjob.

One or more cron events have missed their schedule.

Warning saying crons are not running

Let's see how we can set up cronjob easily for your WordPress website.

Step 1

The first thing, we need to do is disable wp-cron from the wp-config,php file. Please add the following line

define('DISABLE_WP_CRON', 'true');

We need to disable wp-cron in wp-config.php

You can either access the file through the file manager option in RunCloud or from SSH.

Now, if you access the WordPress dashboard of plugins like wp control then it will show the below warning. This is expected, nothing to worry about.

This is expected


Step 2

As mentioned before, we need to integrate with server cronjob using wp-cli. Luckily, RunCloud already provides us with a UI so we just need to add it as follows. 

Exact configuration for wp-cron in RunCloud

I have set the time interval to 5 but you can change it according to your website. The command used is following

cd /home/runcloud/webapps/app-casper && wp cron event run --due-now > /dev/null 2>&1

You can replace runcloud with your web application owner and app-casper with your web application name.

The cronjob should now be operational, and the WordPress dashboard should display all cronjobs without error. 

We can see it's running fine



Conclusion

In conclusion, creating a WP cronjob from the RunCloud dashboard using WP-CLI is a simple and efficient way to automate various tasks on your WordPress website. This method allows you to easily set up and manage your cronjobs without having to manually edit the cron file or use any third-party tools. Additionally, using WP-CLI offers a more user-friendly and intuitive interface compared to the traditional method of creating cronjobs. Overall, utilizing WP-CLI and the RunCloud dashboard is a convenient and effective solution for managing your WordPress cronjobs.


Comments

  1. This works perfectly

    ReplyDelete
  2. This is a better way of doing cron for WordPress because it will work even when our website is behind .htpasswd authentication. Thank you for the post!

    ReplyDelete

Post a Comment