Setting Up Cron Jobs
Schedule recurring tasks - WordPress cron, database cleanups, backup scripts, and custom commands.
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
- Log into cPanel
- Go to Advanced → Cron Jobs
- Under Add New Cron Job, set the schedule
- Enter the command
- 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
| Schedule | Cron Expression | Use Case |
|---|---|---|
| Every 5 minutes | */5 * * * * | WordPress cron, queue workers |
| Every hour | 0 * * * * | Cache clearing, status checks |
| Daily at 3am | 0 3 * * * | Database backups, log rotation |
| Weekly (Sunday midnight) | 0 0 * * 0 | Weekly 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
When using a cron job for WordPress, disable the built-in WP cron by adding this to wp-config.php:
define('DISABLE_WP_CRON', true);
This prevents WP from running cron on every page load, which improves performance.
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
| Command | What It Does |
|---|---|
crontab -l | List all cron jobs for the current user |
crontab -e | Edit cron jobs |
crontab -r | Remove all cron jobs (careful!) |
sudo crontab -l -u www-data | List cron jobs for a specific user |
Troubleshooting
| Problem | Fix |
|---|---|
| Cron job not running | Check the command works manually first. Use full paths (e.g., /usr/local/bin/php not just php) |
| Permission denied | Make sure the script is executable (chmod +x) and the user has access |
| Getting empty emails | The command produces no output. This is fine - or redirect to a log file instead of /dev/null |
| Wrong timezone | cPanel cron uses server time. Check General → Server Time in cPanel |
| Command works manually but not in cron | Cron runs with a minimal environment. Use full paths for all binaries and files |
What to Do Next
- Installing WordPress - set up WP-Cron properly
- Backups and Restores - automate your backup schedule
Last updated 05 Apr 2026, 00:00 +0200.