A cron job runs a command on a schedule: for example, a PHP script every night, or WordPress's scheduled tasks every 15 minutes.
Container Hosting: open the Cron jobs tab, add the job, then press Save. DirectAdmin hosting: use Cron Jobs in DirectAdmin. Always use full paths, and avoid running jobs more often than you need.
1. Container Hosting
- Open your containerin the client area and go to the Cron jobs tab.
- Add a job.Choose a preset or type a schedule, then enter the command.
- Press Save.Changes wait until you save, so you can add or remove several jobs at once.
To run a PHP script, call PHP with the full path to the script:
php /home/<your user>/public_html/cron.phpA command cannot contain a % character or a line break. More detail is in PHP Settings and Cron Jobs.
2. DirectAdmin hosting
- Log in to DirectAdminand open Cron Jobs (under Advanced Features or Extra Features, depending on your skin).
- Enter the schedule(minute, hour, day of month, month, day of week) and the command.
- Click Create(or Add).
3. The schedule format
* * * * *
| | | | └── day of week (0-7, 0 and 7 = Sunday)
| | | └──── month (1-12)
| | └────── day of month (1-31)
| └──────── hour (0-23)
└────────── minute (0-59)| Schedule | Runs |
|---|---|
| /15 * | Every 15 minutes |
| 0 /6 | Every 6 hours |
| 30 2 * | Every day at 02:30 |
| 0 9 1 | Every Monday at 09:00 |
| 0 0 1 | First day of each month at midnight |
4. WordPress cron
WordPress runs its scheduled tasks when someone visits the site. On a quiet site they can run late. To run them on time:
- Add
define('DISABLE_WP_CRON', true);towp-config.php. - Add a cron job every 15 minutes that runs
php /home/<your user>/public_html/wp-cron.php.
5. Good habits
- Use full paths for PHP, scripts and files.
- Don't run jobs too often. Every minute is rarely needed and uses your plan's resources.
- Keep the output. Send it to a log file, for example
>> /home/<your user>/logs/cron.log 2>&1, so you can see what happened.
My Container Hosting cron job does not run. What should I check?
Check that you pressed Save, that the command uses full paths and contains no % character, and look in the Logs tab for errors.
How often can a cron job run?
At most once a minute, but choose the longest interval that does the job.