How to Set Up Cron Jobs
Schedule automated tasks on your GoZen Host server using cron jobs. Covers cPanel, Enhance, and command-line setup.
Cron jobs let you schedule commands to run automatically at specific times on your GoZen shared hosting or VPS. Use them for database backups, cleanup scripts, sending scheduled emails, or running WordPress maintenance tasks.
Cron Jobs in cPanel
- Log in to cPanel
- Go to Advanced > Cron Jobs
- Set the schedule using the time fields:
| Field | What It Means | Example |
|---|---|---|
| Minute | 0-59 | 0 = top of the hour |
| Hour | 0-23 | 3 = 3 AM |
| Day | 1-31 | 1 = first of the month |
| Month | 1-12 | * = every month |
| Weekday | 0-7 (0 and 7 = Sunday) | 1 = Monday |
- Enter the command
- Click Add New Cron Job
Common Cron Schedules
| Schedule | Minute | Hour | Day | Month | Weekday |
|---|---|---|---|---|---|
| Every 5 minutes | */5 | * | * | * | * |
| Every hour | 0 | * | * | * | * |
| Every day at 3 AM | 0 | 3 | * | * | * |
| Every Monday at midnight | 0 | 0 | * | * | 1 |
| First of every month | 0 | 0 | 1 | * | * |
Common Cron Commands
Run WordPress cron (replace WP’s built-in pseudo-cron):
/usr/local/bin/php /home/username/public_html/wp-cron.php > /dev/null 2>&1
Back up a database daily:
/usr/bin/mysqldump -u dbuser -p'password' database_name > /home/username/backups/db_$(date +\%Y\%m\%d).sql
Delete old log files (older than 30 days):
find /home/username/logs/ -name "*.log" -mtime +30 -delete
Clear the WordPress transient cache:
/usr/local/bin/wp transient delete --all --path=/home/username/public_html/
Output suppression: Add
> /dev/null 2>&1to the end of commands to prevent cron from sending you an email every time it runs.
Cron Jobs on a VPS (Command Line)
On a VPS with SSH access, use the crontab command:
# Edit your cron jobs
crontab -e
# List current cron jobs
crontab -l
Crontab Syntax
# m h dom mon dow command
0 3 * * * /usr/local/bin/php /var/www/yourdomain.com/wp-cron.php
0 */6 * * * /usr/bin/certbot renew --quiet
30 2 * * 0 /home/user/scripts/weekly-backup.sh
System-Wide Cron Jobs
For root-level tasks:
sudo nano /etc/crontab
Or place scripts in the appropriate directory:
| Directory | Runs |
|---|---|
/etc/cron.hourly/ | Every hour |
/etc/cron.daily/ | Every day |
/etc/cron.weekly/ | Every week |
/etc/cron.monthly/ | Every month |
WordPress and Cron
WordPress uses a “pseudo-cron” system (wp-cron.php) that runs on every page load. This is inefficient because:
- It adds processing time to every page load
- It doesn’t run if nobody visits your site
- It can cause duplicate execution under high traffic
Better approach: Disable WP-Cron and use a real server cron:
Add to
wp-config.php:define('DISABLE_WP_CRON', true);Add a cPanel cron job (every 5 minutes):
*/5 * * * * /usr/local/bin/php /home/username/public_html/wp-cron.php > /dev/null 2>&1
Troubleshooting
| Problem | Fix |
|---|---|
| Cron not running | Check the command path. Use full paths (e.g., /usr/local/bin/php, not just php). |
| Getting email every time cron runs | Add > /dev/null 2>&1 to suppress output |
| Command works manually but not in cron | Cron uses a minimal environment. Use absolute paths for everything. |
| Permission denied | Make sure scripts are executable: chmod +x script.sh |
Related Articles
Last updated 19 Apr 2026, 23:46 +0300.