How to Set Up a Cron Job
What is a Cron Job?
A cron job is a scheduled task that runs automatically at specified intervals. Common uses:
- Running a backup script
- Clearing a cache
- Sending automated emails
- Running a PHP maintenance script
Setting Up in DirectAdmin
- Log in to DirectAdmin
- Go to Advanced Features → Cron Jobs
- Click Create a Cron Job
- Set the schedule:
- Enter the command to run
- Click Create
Common Examples
Run a PHP script every hour:
0 /usr/local/bin/php /home/username/domains/example.com/public_html/cron.php
Run a script every day at midnight:
0 0 * /usr/local/bin/php /home/username/domains/example.com/public_html/daily.php
Run a script every 5 minutes:
/5 * /usr/local/bin/php /home/username/domains/example.com/public_html/check.php
Tips
- Use full paths for both the PHP binary and your script
- Use
>/dev/null 2>&1at the end to suppress email output - Test your script manually via SSH first before scheduling it
Was this article helpful?