Cron jobs allow you to automate repetitive tasks like running scripts, sending emails, or updating data. This guide covers the basics of setting up cron jobs in cPanel.
Step-by-Step Guide:
-
Log in to your cPanel.
-
In the "Advanced" section, click on "Cron Jobs."
-
Set Up an Email for Notifications (Optional):
-
Enter an email address to receive cron output. If left blank, no emails will be sent.
-
-
Add a New Cron Job:
-
You have two options:
-
Common Settings: Choose a predefined interval (e.g., Once Per Day). This auto-fills the timing fields.
-
Custom Settings: Manually enter the minute, hour, day, month, and weekday.
-
-
Understanding the Timing Syntax:
-
Minute: (0-59)
-
Hour: (0-23)
-
Day: (1-31)
-
Month: (1-12)
-
Weekday: (0-7) (Sunday is 0 or 7)
Examples:
-
0 0 * * *- Runs daily at midnight. -
*/5 * * * *- Runs every 5 minutes. -
0 2 * * 1- Runs at 2 AM every Monday.
Enter the Command:
This is the actual script or command you want to run. Examples:
-
Run a PHP script:
php /home/username/public_html/script.php -
Run a WordPress cron:
wget -q -O /dev/null https://yourdomain.com/wp-cron.php?doing_wp_cron -
Run a Python script:
python /home/username/public_html/myscript.py
Important Notes:
-
Always use the full absolute path to files.
-
Test your command manually before setting up the cron job.
-
If your script requires specific environment variables, you may need to source them in the command.