It is a common question we are getting from the elgg community, to help people in setting up elgg cron jobs in their installation. You may not be aware that Elgg requires a cron to be run. But actually it needs. For those new comers here is an introduction to cron, its purpose, and how to set it up.
What is Cron / Cron job?
Cron is a unix utility that allows some tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix. Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times. You can see such a file inside the elgg download package.
Why do I need Cron?
Configuring cron is an extremely important task in your Elgg website setup. Cron is essential for some modules like logrotate, garbage collector etc.. which are required t keep a log of your users activity on the site, remove orphan entries from the databases etc.. Some third party modules like anti spam tools also require cron to remove the previous banned IP’s from the database. With a properly set cron you can send your users birthday wishes, regular email alerts etc.. You can set a command or script to run at a specific time every day, week, etc. For example, you could set a cron job to delete temporary files every week to free up disk space.For the Team Webgalli site, we are using a daily cron job to optimize the DB Tables, Clean up the orphan DB data, Truncate unnecessary DB tables, Post a tweet daily from our latest blog, Clean up old cache and junk datas from disk etc…
How to set up Cron?
Actually it is very easy thing. There are multiple ways of setting up a cron. Here we will explain it on a cPanel based system. You can do it by
- login to your cPanel >
- Find the Cron Jobs button (usually it is under the advanced tab).
- Open the link.
Here you will able to see three options .
1) Cron Email
Enter your email address here, so that the system will send you the result of the cron job once the cron runs. You can change this email anytime. If you do not want an email to be sent for an individual cron job you can redirect the command’s output to /dev/null like this: mycommand >/dev/null 2>&1
2) Add new cron job
Here you will see a pull down called common settings. Select one of it (these can be every minute, every five minute, every day, every month etc..) Also note that some hosting providers wont provide the every minute or every five minute (small durations). Now in the command area enter the code as follows (click on the image for a bigger resolution)
This will tell the system to call the page http://mysitename.com/cron/daily at the intervals you specified. The allowed intervals in Elgg are minute, fiveminute , fifteenmin, halfhour, hourly, daily, weekly, monthly, yearly and on reboot.
3) Current cron jobs
This will show you the latest cron jobs installed. You can edit / remove cron jobs from here.
- There is a cron checker plugin available in the elgg community for you to install and make sure your cron is running.
- Do not use very short duration cron jobs in a shared host or unnecessarily. Because consumes more server load and makes your site slow. Use only needed cron jobs. For a basic elgg installation, you only need monthly cron.
- There is a good documentation available on elgg about cron and how to Develop Cron-aware plugins