CronAutomationcPanel4 min read

Schedule tasks with Cron Jobs in cPanel

Create cron jobs, common schedules, PHP scripts via cron and troubleshooting.


What are Cron Jobs?

Cron Jobs are scheduled tasks that run automatically at defined intervals. They are useful for backups, sending emails, cache cleanup, data updates and more.

Create a Cron Job in cPanel

  1. Log in to cPanel
  2. Go to AdvancedCron Jobs
  3. Configure the schedule:
  • Minute: 0-59
  • Hour: 0-23
  • Day of month: 1-31
  • Month: 1-12
  • Day of week: 0-6 (0 = Sunday)
  1. Enter the command
  2. Click Add New Cron Job

Common schedules

FrequencyMinuteHourDayMonthWeek
Every 5 minutes*/5****
Every hour0****
Daily at 3 AM03***
Weekly (Monday)02**1
Monthly (1st)041**

cPanel also offers shortcuts: "Once Per Minute", "Once Per Hour", "Once Per Day", etc.

Run PHP scripts via Cron

bash
# Run a PHP script
/usr/local/bin/php /home/user/public_html/script.php

# With specific PHP version
/usr/local/bin/ea-php83 /home/user/public_html/cron/task.php

# Pass parameters
/usr/local/bin/php /home/user/public_html/cron/send-emails.php --type=newsletter

WordPress Cron

WordPress has its own cron system that depends on visits. To make it more reliable:

  1. Disable WordPress cron in wp-config.php:
php
define('DISABLE_WP_CRON', true);
  1. Create a real cron in cPanel:
bash
# Run wp-cron every 5 minutes
*/5 * * * * /usr/local/bin/php /home/user/public_html/wp-cron.php > /dev/null 2>&1

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

Email notifications

By default, cron sends an email with the output of each execution.

Configure notification email

In the Cron Email section, enter your email address.

Silence the output

If you do not want to receive emails:

bash
# Redirect all output to /dev/null
/usr/local/bin/php /home/user/script.php > /dev/null 2>&1

Only receive errors

bash
# Redirect stdout but keep stderr
/usr/local/bin/php /home/user/script.php > /dev/null

Troubleshooting

Cron does not execute

  1. Verify the full path to the PHP interpreter:
bash
which php
# Typical result: /usr/local/bin/php
  1. Verify script permissions:
bash
chmod 755 /home/user/public_html/cron/script.php
  1. Test the command manually via SSH:
bash
/usr/local/bin/php /home/user/public_html/cron/script.php

Common errors

  • Permission denied: Check file permissions (755)
  • No such file: Use full absolute paths
  • PHP Fatal error: Check the script for syntax errors

Practical examples

bash
# Daily database backup
0 3 * * * mysqldump -u user -pPASS dbname > /home/user/backups/db-$(date +\%Y\%m\%d).sql

# Clean temporary files weekly
0 4 * * 0 find /home/user/public_html/tmp -type f -mtime +7 -delete

# Send weekly report
0 9 * * 1 /usr/local/bin/php /home/user/public_html/cron/weekly-report.php

Recommendations

  • Always use absolute paths in commands
  • Redirect output to avoid unnecessary emails
  • Do not schedule heavy tasks during high-traffic hours
  • Document each cron job with a comment in the command
  • Periodically verify that crons are executing correctly

Was this guide helpful?