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.
On this page
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
- Open Advanced Features › Cronjobs.
- Fill in the five schedule fields.
- Enter the command.
- Select Create.
The schedule fields
| Field | Allowed | Example |
|---|---|---|
| Minute | 0–59 | 0 |
| Hour | 0–23 | 3 |
| Day of month | 1–31 | * |
| Month | 1–12 | * |
| Day of week | 0–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.phpAlways 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>&1To keep a log instead:
/usr/local/bin/php /path/to/script.php >> /home/USERNAME/logs/cleanup.log 2>&1Be 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?
- Schedule a task with a cron job
Intermediate · 20 min - Deploy a Laravel application to Traxio
Advanced · 60 min
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.