Cron Jobs

    Automate scheduled tasks on your hosting account

    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

    1. Log into cPanel
    2. Find "Advanced" section
    3. Click "Cron Jobs"
    4. Set up email notification (optional but recommended)
    5. Choose timing using:
      • Common Settings dropdown (easy presets), or
      • Manual timing settings (advanced)
    6. Enter the command to run
    7. 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 * * 1

    Twice 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.php

    Using wget to Access URL

    wget -q -O /dev/null https://yourdomain.com/cron.php

    Using curl to Access URL

    curl -s https://yourdomain.com/cron.php

    Running Shell Scripts

    /bin/sh /home/username/scripts/backup.sh

    WordPress 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_cron

    Email 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>&1

    Logging Output to File

    command >> /home/username/cron.log 2>&1

    Managing Cron Jobs

    Editing Cron Jobs

    1. Go to Cron Jobs in cPanel
    2. Find the cron job in the list
    3. Click "Edit"
    4. Modify timing or command
    5. Click "Edit Line"

    Deleting Cron Jobs

    1. Go to Cron Jobs in cPanel
    2. Find the cron job in the list
    3. Click "Delete"
    4. 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.