Skip to content
RIPE NCC member · Local Internet RegistryCall us on 020 3318 3449sales@hosting-telecom.uk

Cron: running scripts on a schedule

Scheduled tasks in cPanel and on your own server: the line format, examples, and why a job might not run.

Contents

Cron runs commands and scripts on a schedule: every ten minutes, every night, every Monday. On web hosting you add jobs in cPanel; on your own server you use the crontab command.

In cPanel

Go to Advanced → Cron Jobs. Pick a schedule from the ready-made options or fill in the fields by hand, then enter what to run in the Command field:

/usr/local/bin/php /home/username/public_html/cron.php

/usr/local/bin/php is the default PHP version. If your script needs a particular version, give its path instead — for PHP 8.3, for example: /opt/cpanel/ea-php83/root/usr/bin/php. cPanel emails the output of each job to the address set in the same section; to stop the emails, add >/dev/null 2>&1 to the end of the command.

Line format

minute  hour  day_of_month  month  day_of_week  command

An asterisk means “any value”, */10 means “every 10”, and days of the week run from 0 (Sunday) to 6. Times follow the server’s clock.

# every 10 minutes
*/10 * * * * /usr/local/bin/php /home/username/public_html/cron.php
# every day at 03:30
30 3 * * * /usr/local/bin/php /home/username/public_html/cron.php
# every Friday at midnight
0 0 * * 5 /usr/local/bin/php /home/username/public_html/cron.php
# on the first day of every month at 00:00
0 0 1 * * /usr/local/bin/php /home/username/public_html/cron.php

Why a job doesn’t run

  • Relative paths. Cron doesn’t run commands from your website’s folder, and its PATH holds only a short list of directories. Use full paths to the program (/usr/local/bin/php, not php), to the script, and to any files the script opens. In PHP it’s handy to build paths from __DIR__.
  • An asterisk in the minutes field. * 3 * * * means every minute from 03:00 to 03:59, not once during the night. You need 0 3 * * *.
  • You can’t see any errors. Save the output to a file: … >> /home/username/cron.log 2>&1 — and look at what the script writes.
  • No permission to run. A script that runs directly, rather than through php, must be executable (chmod 755 script.sh) and start with a line such as #!/bin/bash.
  • A file from Windows. If you edited the script in Windows, it may fail because of the line endings — see Files from Windows: line endings for the fix.

On your own server

crontab -e   # open your jobs in an editor
crontab -l   # list your jobs

To run jobs as root, use sudo crontab -e. If the crontab command is missing, install cron: sudo apt install cron on Debian and Ubuntu, or sudo dnf install cronie on AlmaLinux. To see the log of runs, use journalctl -u cron (Debian, Ubuntu) or journalctl -u crond (AlmaLinux); on FreeBSD the log is the file /var/log/cron.

Didn’t find the answer? Ask our support team — we’ll help.

Choose which cookies we may use. You can change your mind at any time with the “Cookie settings” link at the bottom of every page.

Necessary

Always active

They keep the site secure and remember your cookie choice. They don’t identify you.

Google Analytics counts visits and shows which pages people find useful, so we can improve the site. Which cookies