Ahosting Logo
Knowledge Base

How to Set Up Cron Jobs in cPanel

Cron jobs are scheduled tasks that run automatically at specified times. They are useful for automating repetitive tasks like backups, sending emails, or running maintenance scripts.

What Can You Automate?

  • Database backups
  • Email newsletters
  • Cache clearing
  • Report generation
  • Data imports/exports
  • WordPress scheduled tasks (wp-cron alternative)

Accessing Cron Jobs

  1. Log into cPanel
  2. Go to Advanced section
  3. Click Cron Jobs

Understanding Cron Timing

Cron uses five time fields:

Field Values Example
Minute 0-59 30 (at 30 minutes past)
Hour 0-23 14 (2 PM)
Day of Month 1-31 1 (first of month)
Month 1-12 * (every month)
Day of Week 0-6 (Sun-Sat) 1 (Monday)

* means every (e.g., * in hour field = every hour)

Common Cron Schedules

# Every minute
* * * * *

# Every hour
0 * * * *

# Every day at midnight
0 0 * * *

# Every day at 3 AM
0 3 * * *

# Every Monday at 9 AM
0 9 * * 1

# First day of month at midnight
0 0 1 * *

# Every 5 minutes
*/5 * * * *

# Every 30 minutes
*/30 * * * *

Creating a Cron Job

  1. In Cron Jobs, choose Common Settings dropdown or set custom timing
  2. Enter the command to run
  3. Click Add New Cron Job

Example Commands

Run a PHP Script

/usr/local/bin/php /home/username/public_html/script.php

Run WordPress Cron

wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Curl a URL

curl -s https://yourdomain.com/cron-task.php >/dev/null 2>&1

Cron Email Notifications

By default, cron sends output via email. To set the email:

  1. At the top of Cron Jobs page, enter email in Cron Email
  2. Click Update Email

To disable email output, add this to end of command:

>/dev/null 2>&1

Editing a Cron Job

  1. Find the cron job in the list
  2. Click Edit
  3. Modify timing or command
  4. Click Edit Line

Deleting a Cron Job

  1. Find the cron job
  2. Click Delete
  3. Confirm deletion

Troubleshooting

  • Script not running: Check file path is correct (use full path)
  • Permission denied: Set script permissions to 755
  • No output: Remove >/dev/null temporarily to see errors
  • Wrong time: Server uses UTC timezone