Cron jobs are planned tasks which you can run automatically on certain moments of the day, for example, an import script. Within DirectAdmin, you can set up cron jobs, change or delete them.
Set up cron jobs
1. Log in to DirectAdmin.
2. In the menu, go to 'Advanced Features' → 'Cron Jobs'.
3. Click on 'Create cron job' and fill out the form.
- Minute, Hour, Day of the Month, Month and Day of the Week: Specify the minute, hour, day of the month, month and day of the week (respectively) on which the script needs to run. The last one stands for Sunday through Sunday. Sunday is either 0 or 7. You can read more below on setting the times.
- Command: The command which needs to be run. A PHP script starts with /usr/local/bin/php. You can click on 'Prevent e-mail' to prevent the script from sending e-mails to your main e-mail address with an output of the script (for example, errors). You can read more below on commands.
4. After you have entered all the required details for your cron job, locate and click the 'Create' button.
Configuring Run Times
When scheduling your cron job, it is important not to use standard or common times for execution. Avoid scheduling your script at predictable times such as every full hour or every quarter-hour (e.g., 2:00, 1:30, or 0:00). These are peak moments when many other cron jobs may also run, potentially leading to high server load.
Instead, choose a less busy time window, typically between 4:00 and 6:00 AM, and select a random minute, such as 4:34. This helps distribute system load more evenly throughout the day, ensuring better performance and reliability.
Additionally, make sure your script runs only as often as necessary. Each cron job can be resource-intensive, and excessive use may negatively impact server performance. Note that cron jobs can only run once per hour, so plan accordingly.
Finally, avoid setting your script to run every minute. Using an asterisk (*) in the minute field is not allowed.
You can specify the desired schedule in the form as follows:
| 2 | The second minute, hour, etc. |
| 1,2 | The first and second minute, hour, etc. |
| * | Every minute, hour, etc. |
| */2 | Every second minute, hour, etc. |
| 1-3 | From the first up to and including the third minute, hour, etc. |
| 1,*/6,5-9 | A combination of the above examples (runs at minute 1, every 6 minutes, and from minute 5 to 9). |
You can fill out these values with all time units, so at the minutes, hours, days of the month and days of the week. For example, if you want to run your script every second month on the first Monday of the month at 4:15 and 9:15, you can use the following settings:
| Minute | 15 | Runs at the 15th minute of the hour. |
| Hour | 4, 9 | Runs at 4:00 and 9:00. |
| Day of Month | 1-7 | The first Monday occurs between the 1st and 7th day of the month. |
| Month | */2 | Every second month. |
| Day of Week | 1 | Monday (0 = Sunday, 1 = Monday, ..., 6 = Saturday) |
Scripts and commands
Cron jobs can only execute executable files directly. Since PHP scripts are not executable by default, you must call the PHP module first. The PHP binary is located at:
/usr/local/bin/phpTo run a PHP script located in your public_html directory, use a command like the following. Be sure to replace username with your DirectAdmin username and example.com with your actual domain name:
/usr/local/bin/php /home/username/domains/example.com/public_html/script.phpNote: There is a space between the PHP binary path and the script path.
Any output generated by your script will be sent to the primary email address associated with your DirectAdmin account.
Keep in mind that cron jobs run in a different environment than a web request. Some key differences include:
Relative paths will not work — always use absolute paths in your scripts.
Certain environment variables (such as
$_SERVERvalues) may be missing or different from a normal browser request.
You can also trigger a script via an HTTP request, similar to how a visitor would access your site. Use the following command (replacing example.com with your domain):
/usr/local/bin/wget -0 - -q -t 1 "https://example.com/script.php"This approach avoids issues with relative paths since the request goes through your web server. However, keep in mind:
The script becomes publicly accessible, meaning anyone could potentially trigger it.
This method is not recommended for cron jobs that need to run frequently (more than once per day).
Network traffic generated this way is counted twice — once for the upload and once for the download — which may affect bandwidth usage.
This method should be used only as a last resort, for example, when running the PHP module directly does not work.