How to Create and Manage CRON Jobs

CRON Jobs allow you to schedule automatic tasks on your server, such as database backups, clearing cache, and running scripts.

Step 1: Create a CRON Job in cPanel

1️⃣ Log in to cPanel.
2️⃣ Go to Cron Jobs under the "Advanced" section.
3️⃣ In the Common Settings dropdown, choose how often the job runs (e.g., Once per day).
4️⃣ Enter the command to execute. Example:

php /home/username/public_html/cron_script.php

5️⃣ Click Add New Cron Job.

Step 2: CRON Job Examples

Run a script every 5 minutes:

*/5 * * * * php /home/username/public_html/script.php

✅ Delete old logs every day at midnight:

0 0 * * * rm -rf /home/username/public_html/logs/*.log

✅ Backup the database every week:

0 0 * * 0 mysqldump -u user -p'password' database > /home/username/backups/db_backup.sql

✅ Check for WordPress updates every hour:

0 * * * * wp core update --path=/home/username/public_html/

Tip: Be careful with CRON jobs. A poorly written command can overload your server!

 

  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

Understanding PHP Versions and How to Change Them

Advanced server management allows developers and system administrators to have better control...

How to Use SSH to Access Your Server

SSH (Secure Shell) provides secure remote access to your server, allowing you to execute...

How to Install & Manage Node.js or Python Apps

SiteGete Hosting supports Node.js and Python applications, allowing you to run modern web...