Setting Up a CRON Job for Magento

Cron jobs are automated events that are triggered by the server. A lot of people think that the Magento cron runs automatically – but this is not the case.

When you have finished your Magento website and set it live on a server you MUST activate the Magento Cron – otherwise you may notice that the following functionality fails to work:

  • Newsletter
  • Sitemap Generation
  • Other extensions that rely on cron settings

To set up your cron you need to tell your server to execute Magento’s cron.php file every so often – normally every 10 minutes or 20 minutes – you can change this depending on how long it takes your cron to run (normally only a couple of seconds but if you have extensions that do a lot of processing you may want to extend the time between runs – the last thing you want is for a cron to overlap!).

I’m going to show you how to set this up within a Plesk control panel.

First of all navigate to your domain and then click on Crontab (sometimes called ‘Scheduled Tasks’). Within Crontab will be a list of users for the domain (normally your FTP users) – click on a user and then click on Schedule a Task for <user> (or sometimes just ‘Schedule New Task’).

This next page can be quite complicated to understand but essentially it’s where we are going to set the time and dates for our cron to run – and also the command that will be ran.

For a Magento cron we only really want it to run every 10 minutes or so. To do this we can enter the following into the fields:

  • Switched on = checked
  • Minute = */10 (star means ‘every’ – so here we’ve said every 10 minutes)
  • Hour = *
  • Day of the Month = *
  • Month = *
  • Day of the Week = *
  • Command = /usr/bin/php -f /var/www/vhosts/mydomain.com/httpdocs/cron.php
cron-task2

So, above we have set our cron task to run every 10 minutes, every hour, every day, every month and to run the command:

/usr/bin/php -f /var/www/vhosts/mydomain.com/httpdocs/cron.php

Or alternatively (and probably better in my opinion) run it via CURL:

/usr/bin/curl http://www.mydomain.com/magentofolder/cron.php

Please note that you must edit this command to match your own server setup – it’s the path from the root of the server to the cron.php residing in your Magento installation (don’t copy/paste!).

That is pretty much all you need to do to get your cron up and running. I hope you enjoyed this quick tutorial!