Talk to a real engineer in Agra, 24×7 — +91 75994 50220 support@bigdomainhost.com
Guide

Cron jobs explained, and how to set one up

A cron job is a command your server runs on a schedule. The concept takes a minute; the five-field syntax is what trips everyone up. Here is both, plus the four reasons a cron that looks right does not run.

What it is

Cron is the scheduler that has been part of Unix since the 1970s. It reads a table of jobs — the crontab — and runs each command when its schedule comes round. That is the whole idea.

What people use it for, in practice: nightly backups, clearing temp files, importing a supplier feed, sending invoice reminders on the first of the month, renewing certificates, and driving WordPress's scheduler properly.

The five fields

┌───────────── minute        (0 - 59)
│ ┌─────────── hour          (0 - 23)
│ │ ┌───────── day of month  (1 - 31)
│ │ │ ┌─────── month         (1 - 12)
│ │ │ │ ┌───── day of week    (0 - 6, Sunday = 0)
│ │ │ │ │
* * * * *  /usr/bin/php /home/user/script.php

Four operators, and that is the entire syntax:

  • * — every value. * * * * * is every minute.
  • , — a list. 0 9,17 * * * is 9am and 5pm.
  • - — a range. 0 9-17 * * * is hourly from 9am to 5pm.
  • / — a step. */15 * * * * is every fifteen minutes.

Schedules you will actually use

ExpressionRuns
*/5 * * * *Every five minutes
*/15 * * * *Every fifteen minutes — the usual WP-Cron replacement
0 * * * *Every hour, on the hour
30 2 * * *2:30am daily — the classic backup slot
0 3 * * 03am every Sunday
0 0 1 * *Midnight on the first of every month
0 9 * * 1-59am on weekdays only

Cron runs in the server's timezone. On our servers that is IST, so 30 2 * * * is 2:30am in India, not UTC. Check with date before you assume.

Setting one up in cPanel

  1. cPanel → Cron Jobs.
  2. Put an address in Cron Email. Cron mails you anything the command prints, which is how you find out it has been failing for three weeks.
  3. Pick a Common Setting, or type the five fields yourself.
  4. Enter the command with absolute paths:
    /usr/local/bin/php /home/username/public_html/cron.php
  5. Add the job, then wait for the first run and check the mail.

To silence a job that works and prints noise, append >/dev/null 2>&1 — but only once you have seen it succeed.

On a VPS

# edit your own crontab
crontab -e

# list what is scheduled
crontab -l

# run as another user
sudo crontab -u www-data -e

System-wide jobs live in /etc/cron.d/ and take an extra field — the user to run as — between the schedule and the command. That difference catches people out constantly.

The four reasons it does not run

1. Relative paths

Cron does not start in your home directory and does not have your shell's PATH. php script.php fails; /usr/local/bin/php /home/user/script.php works. Find the binary with which php and use what it prints.

2. A missing environment

Your interactive shell loads .bashrc; cron does not. Anything that depends on an environment variable needs it set in the crontab itself:

PATH=/usr/local/bin:/usr/bin:/bin
30 2 * * * /home/user/backup.sh

3. The script is not executable

chmod +x /home/user/backup.sh, and make sure the first line is a shebang: #!/bin/bash.

4. An unescaped percent sign

The one nobody guesses. In a crontab, % means a newline. A command containing date +%Y-%m-%d is silently cut off at the first percent. Escape every one as \%.

WordPress: replace WP-Cron

WordPress's scheduler is not cron. It fires when someone loads a page, so on a quiet site scheduled posts do not publish and backups do not run — and on a busy site it fires on every page load, which is its own problem.

Fix both at once. In wp-config.php:

define('DISABLE_WP_CRON', true);

Then add a real cron job every fifteen minutes:

*/15 * * * * /usr/local/bin/php /home/user/public_html/wp-cron.php >/dev/null 2>&1

This is one of the highest-value five-minute changes on a WordPress site, and it is covered in more depth in our WordPress speed guide.

Debugging one that has gone quiet

  • Check the cron log — /var/log/syslog on Debian and Ubuntu, /var/log/cron on AlmaLinux and Rocky.
  • Redirect output to a file and read it: >> /home/user/cron.log 2>&1.
  • Run the exact command by hand first. If it fails interactively, cron was never the problem.
  • Test with * * * * * so you find out in a minute rather than tomorrow, then set the real schedule.

Cron jobs are available on every plan we sell, from shared cPanel upwards. If one will not behave, call +91 75994 50220 and we will look at it with you.

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies, 24×7.

What is a cron job?

A command scheduled to run automatically at fixed times or intervals. Backups at 2am, an invoice run on the first of the month, a feed imported every fifteen minutes — anything that should happen without someone remembering to do it.

How do I read cron syntax?

Five fields before the command: minute, hour, day of month, month, day of week. An asterisk means every value. So 30 2 * * * is 2:30am daily, and */15 * * * * is every fifteen minutes.

How do I set up a cron job in cPanel?

cPanel → Cron Jobs. Pick a common setting or type the five fields, put the full command in the box, and set an email address for the output. Always use absolute paths — cron does not have your shell PATH.

Why is my cron job not running?

Almost always one of four things: a relative path instead of an absolute one, a missing PATH environment variable, the script not being executable, or an unescaped percent sign — in crontab, % means a newline and silently truncates your command.

What is WP-Cron and should I replace it?

WordPress has its own scheduler that fires on page loads, so on a quiet site scheduled posts and backups never run. Disable it in wp-config.php and call wp-cron.php from a real cron job every fifteen minutes instead.

What is the minimum cron interval?

One minute, on standard cron. Anything finer needs a long-running process or a loop with sleep. On shared hosting the practical minimum is often five or fifteen minutes to protect the server.

Support that picks up the phone.

24×7, from our office in Agra, in IST — Hindi or English. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Want this done for you?

Migration is free and we do it. Call +91 75994 50220 or email support@bigdomainhost.com.