Tips & Tricks

How to Set Up Cron Jobs in cPanel to Automate Website Tasks

by dotCanada Team
How to Set Up Cron Jobs in cPanel to Automate Website Tasks

If you find yourself repeatedly running the same task on your website - clearing a cache, sending a scheduled report, or running a maintenance script - a cron job can handle it automatically. Cron is a time-based scheduler built into Linux servers, and cPanel gives you a user-friendly interface to set them up without touching the command line.

What Are Cron Jobs?

A cron job is a command or script that runs automatically at a specified time or interval. The name comes from the Greek word for time - chronos - and the "cron daemon" is the background process on Linux servers that manages these scheduled tasks.

Common use cases include:

  • Running WordPress scheduled tasks (WP-Cron)
  • Sending automated email digests or reports
  • Clearing application caches
  • Running database cleanup scripts
  • Triggering backup scripts
  • Fetching and importing data from external APIs

Finding Cron Jobs in cPanel

Log in to your cPanel account and look for the Cron Jobs icon under the Advanced section. Click it to open the cron job manager.

You will see two sections: a dropdown to set how often to check email output from cron jobs, and a form to add new cron jobs. The form has five timing fields and a command field.

Understanding Cron Syntax

The five timing fields control when your job runs. From left to right they are:

Minute  Hour  Day  Month  Weekday

Each field accepts a number, an asterisk * (meaning "every"), a range like 1-5, or a step like */15 (meaning "every 15").

Here are some common examples:

Schedule Cron Expression
Every minute * * * * *
Every hour (on the hour) 0 * * * *
Every day at midnight 0 0 * * *
Every Monday at 8am 0 8 * * 1
Every 15 minutes */15 * * * *
First day of month at noon 0 12 1 * *

cPanel also offers preset options (Once Per Minute, Once Per Hour, Once Per Day, etc.) in a dropdown above the manual fields, which is useful for common schedules.

Practical Examples

WordPress WP-Cron

WordPress uses a pseudo-cron system called WP-Cron to handle scheduled posts, plugin tasks, and update checks. By default, it only runs when someone visits the site. On low-traffic sites this can cause scheduled tasks to run late.

The fix is to disable WP-Cron and trigger it with a real cron job instead. Add this line to wp-config.php:

define('DISABLE_WP_CRON', true);

Then create a cron job in cPanel running every 15 minutes:

*/15 * * * * php /home/yourusername/public_html/wp-cron.php > /dev/null 2>&1

Replace yourusername with your actual cPanel username and adjust the path to match your WordPress installation.

Clearing a Cache

If your application has a CLI cache-clear command, you can schedule it to run nightly:

0 2 * * * php /home/yourusername/public_html/artisan cache:clear > /dev/null 2>&1

The > /dev/null 2>&1 part discards output so your inbox is not flooded with cron emails.

Running a Backup Script

A simple database backup might look like:

0 3 * * * /usr/bin/mysqldump -u dbuser -pdbpassword dbname > /home/yourusername/backups/db_backup.sql

Common Mistakes to Avoid

  • Using relative paths - always use full absolute paths for both the PHP binary and your script files
  • Wrong PHP version - check which PHP binary corresponds to the version your site uses (/usr/local/bin/php vs /usr/bin/php)
  • Running too frequently - a script that takes 2 minutes to run should not be scheduled every minute
  • Not redirecting output - if you do not suppress output, cPanel will email you every time the job runs, which gets noisy fast

Testing Your Cron Job

Before scheduling, test your command manually via SSH or cPanel Terminal to make sure it runs without errors. Once scheduled, check the email associated with your hosting account for any error output from the first few runs, then suppress it with > /dev/null 2>&1 once you have confirmed everything works correctly.

Cron jobs are a small investment of setup time that pays off every time the task runs without you lifting a finger.

100% Satisfaction Guarantee

We're so confident you'll love dotCanada that we offer a 30-day money-back guarantee. Not satisfied? Get a full refund, no questions asked.

Ready to Get Started?

Join thousands of Canadian website owners who trust dotCanada for reliable, fast web hosting.

Get Started Today