Cron jobs run commands on a schedule - every minute, every hour, once a day, whatever you need. Use them for automated backups, database cleanup, email reports, or running WordPress scheduled tasks.

On Shared Hosting (cPanel)

Adding a Cron Job

  1. Log into cPanel
  2. Go to AdvancedCron Jobs
  3. Under Add New Cron Job, set the schedule
  4. Enter the command
  5. Click Add New Cron Job

Schedule Syntax

cPanel provides dropdowns for common schedules, but you can also set the timing manually:

  * * * * * command
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, 0 and 7 = Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)
  

Common Schedules

ScheduleCron ExpressionUse Case
Every 5 minutes*/5 * * * *WordPress cron, queue workers
Every hour0 * * * *Cache clearing, status checks
Daily at 3am0 3 * * *Database backups, log rotation
Weekly (Sunday midnight)0 0 * * 0Weekly reports, full backups
Monthly (1st at 2am)0 2 1 * *Monthly cleanup, archiving

Common Commands

WordPress cron (recommended over WP’s built-in cron):

  /usr/local/bin/php /home/username/public_html/wp-cron.php >/dev/null 2>&1
  

Database backup:

  /usr/bin/mysqldump -u dbuser -p'password' dbname > /home/username/backups/db-$(date +\%Y\%m\%d).sql
  

Delete old log files (older than 30 days):

  /usr/bin/find /home/username/logs -name "*.log" -mtime +30 -delete
  

Email Notifications

By default, cPanel emails you the output of every cron job. To suppress this, add >/dev/null 2>&1 at the end of your command:

  /usr/local/bin/php /home/username/public_html/wp-cron.php >/dev/null 2>&1
  

To change the notification email, set it in the Cron Email field at the top of the Cron Jobs page.

On a VPS

Use the system crontab directly:

  # Edit the crontab for the current user
crontab -e

# Edit crontab for a specific user (as root)
sudo crontab -u www-data -e
  

Add your schedule line and save. The format is the same as above.

Useful VPS Cron Examples

Let’s Encrypt auto-renewal check (runs twice daily):

  0 */12 * * * certbot renew --quiet
  

Restart a service daily:

  0 4 * * * systemctl restart php8.2-fpm
  

System update check (weekly):

  0 3 * * 1 apt update && apt upgrade -y >/dev/null 2>&1
  

Managing Cron Jobs

CommandWhat It Does
crontab -lList all cron jobs for the current user
crontab -eEdit cron jobs
crontab -rRemove all cron jobs (careful!)
sudo crontab -l -u www-dataList cron jobs for a specific user

Troubleshooting

ProblemFix
Cron job not runningCheck the command works manually first. Use full paths (e.g., /usr/local/bin/php not just php)
Permission deniedMake sure the script is executable (chmod +x) and the user has access
Getting empty emailsThe command produces no output. This is fine - or redirect to a log file instead of /dev/null
Wrong timezonecPanel cron uses server time. Check GeneralServer Time in cPanel
Command works manually but not in cronCron runs with a minimal environment. Use full paths for all binaries and files

What to Do Next

Last updated 05 Apr 2026, 00:00 +0200. history

Was this page helpful?