Small Cron Job Tutorial
I mentioned in my previous post [ New Script – ReviewMe offer notifier ] that I will post a guide on how to handle cron jobs and set them up correctly.
So here it goes …
First of all you need to login to your cPanel account. Usually it’s http://yourwebsite.com:2082 After you login look for Cron. I will explain how to use the Advanced (Unix style) cron interface.
Now let’s explain what all those inputs there are for.
If you read the first line it gives you all the indications you need on how to set up your cron job at the exact time you want or time interval.
So to set up a cron job that executes every minute all you have to do is to enter * in the fields Minute, Hour, Day, Month and Weekday.
To set up a cron job to execute itself every hour you have to put 0 in the Minute field and * in all the other fields.
Hope you got it.
Now the tricky part. What should the cron job do ?
Well … if you want it to run a php script located on your server you have to add this to the command field:
php /path/to/php/script
And an example:
php /home/your-username/public_html/folder/cronjob.php
Other stuff I think it’s important and you should probably do a cron job for it is repairing and optimizing your mysql database(s). Depending on your traffic:
- few visitors : probably add a cron job once a week
- a lot of visitors: at least every 24 hours
- more than Google 😀 : every 12 hours.
Of course these are just examples … just use any time interval you think it’s necessary.
To repair your mysql databases you have to use the following command:
mysqlcheck –auto-repair -u[your cPanel username] -p[your cPanel passwords] database name
And an example with username bob, password 123456 and database bob_wordpress
mysqlcheck –auto-repait -ubob -p123456 bob_wordpress
These are the cron jobs which I think are the most important in maintaining a website.
Here’s what my cron jobs look like:
Of course you can do a lot more.
If you need help on setting up a cron job … place a comment and I will help you.