What are Cron Jobs?
Cron jobs are scheduled tasks that run automatically at specified times or intervals. They're useful for automating repetitive tasks like backups, sending emails, updating data, cleaning databases, or running maintenance scripts.
Common Uses
Automated backups
Scheduled emails/newsletters
Database maintenance
WordPress maintenance
Processing queued jobs
Generating reports
Creating a Cron Job
- Log into cPanel
- Find "Advanced" section
- Click "Cron Jobs"
- Set up email notification (optional but recommended)
- Choose timing using:
- Common Settings dropdown (easy presets), or
- Manual timing settings (advanced)
- Enter the command to run
- Click "Add New Cron Job"
Cron Job Timing
Cron timing consists of 5 fields representing when to run:
* * * * * command
│ │ │ │ │
│ │ │ │ └─── Day of week (0-7, 0 and 7 are Sunday)
│ │ │ └───── Month (1-12)
│ │ └─────── Day of month (1-31)
│ └───────── Hour (0-23)
└─────────── Minute (0-59)Common Timing Examples
Every Minute
* * * * *Every Hour
0 * * * *Every Day at Midnight
0 0 * * *Every Monday at 3 AM
0 3 * * 1Twice Daily (6 AM & 6 PM)
0 6,18 * * *Every 15 Minutes
*/15 * * * *Command Examples
Running PHP Scripts
/usr/bin/php /home/username/public_html/script.phpUsing wget to Access URL
wget -q -O /dev/null https://yourdomain.com/cron.phpUsing curl to Access URL
curl -s https://yourdomain.com/cron.phpRunning Shell Scripts
/bin/sh /home/username/scripts/backup.shWordPress Cron Configuration
By default, WordPress uses wp-cron.php which runs on page loads. For better performance, disable default WP-Cron and use a real cron job:
Step 1: Disable WP-Cron
Add to wp-config.php:
define('DISABLE_WP_CRON', true);Step 2: Set Up Cron Job
Create cron job to run every 15 minutes:
*/15 * * * * wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cronEmail Notifications
Notification Settings
At the top of the Cron Jobs page, you can set an email address to receive cron output:
- Enter your email to receive all cron job output
- Leave blank to disable all emails
- Or redirect output in the command itself
Suppressing Output
To prevent email notifications for a specific cron:
command >/dev/null 2>&1Logging Output to File
command >> /home/username/cron.log 2>&1Managing Cron Jobs
Editing Cron Jobs
- Go to Cron Jobs in cPanel
- Find the cron job in the list
- Click "Edit"
- Modify timing or command
- Click "Edit Line"
Deleting Cron Jobs
- Go to Cron Jobs in cPanel
- Find the cron job in the list
- Click "Delete"
- Confirm deletion
Troubleshooting
Cron Not Running
- Check that timing is correct
- Verify file paths are absolute, not relative
- Ensure script has proper permissions (usually 755)
- Check if PHP path is correct
Permission Denied Errors
- Check file permissions (chmod 755 for scripts)
- Verify you own the files
- Use absolute paths in commands
Best Practices
- • Use absolute paths in all commands
- • Test scripts manually before scheduling
- • Set up email notifications during testing
- • Log cron output to files for debugging
- • Don't run crons too frequently
- • Document what each cron job does
Security Tip
Never run cron jobs as root. Always run them under your user account. Also, be careful with scripts that have database access - ensure they're secure and can't be accessed publicly.
