How to create a cron job in DirectAdmin

Schedule scripts and commands to run automatically with DirectAdmin cron jobs: the schedule fields, the command line, and handling output.

Guide2 min readLast updated
On this page
  1. Steps
  2. The schedule fields
  3. The command
  4. Output and emails
  5. Be considerate with frequency
  6. Common questions

A cron job runs a command on a schedule: nightly clean-ups, sending queued emails, importing feeds, WordPress scheduled tasks. Traxio cron jobs can run as often as every one minute.

Steps

  1. Open Advanced Features › Cronjobs.
  2. Fill in the five schedule fields.
  3. Enter the command.
  4. Select Create.

The schedule fields

FieldAllowedExample
Minute0–590
Hour0–233
Day of month1–31*
Month1–12*
Day of week0–6 (0 = Sunday)*

0 3 * * * runs every day at 03:00 server time. Cron schedule syntax explained (with examples) has more patterns.

The command

To run a PHP script:

/usr/local/bin/php /home/USERNAME/domains/yourdomain.co.uk/public_html/cron/cleanup.php

Always use full paths, because cron doesn’t start in your website folder. Running PHP scripts from cron: paths, output and common mistakes

Output and emails

Cron emails any output to the account’s cron notification address, if one is set. To silence a job that works:

/usr/local/bin/php /path/to/script.php >/dev/null 2>&1

To keep a log instead:

/usr/local/bin/php /path/to/script.php >> /home/USERNAME/logs/cleanup.log 2>&1

Be considerate with frequency

A heavy job every minute uses a lot of your account’s resources. Run things as often as they’re genuinely needed.

Prefer to follow along?

New to Traxio? The PHP hosting page lists the PHP versions, database and tools every account gets.

Common questions

How do I set up a cron job?

In DirectAdmin open Advanced Features › Cronjobs, set the schedule and the command to run. Traxio allows intervals down to one minute. For a PHP script, call the PHP binary with the full path to the file rather than fetching its URL.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going