Setting Up A Cron Job for Magento
A Cron job is a scheduled task, a task that is performed every so often by the server without any user input. Cron jobs are important for lots of different reasons and when it comes to ecommerce they are a godsend.
Magento required Cron jobs for a few different reasons but the most important ones in my opinion are:
- Newsletter Sending
- Automatic Sitemap Generation
What you should do is set up your newsletters and sitemaps as normal through Magento. Schedule your times and basically follow the instructions on screen. When you set your dates/times etc the Cron Job will perform these tasks after that date/time has been reached. It is therefore beneficial to schedule your Cron Job to run every 10-15 minutes.
Magento uses a single file named cron.php to execute all its scheduled tasks – all that is required to be done is to schedule a cron job to execute that php every so often.
At Ecommerce Website Design we use a server that has Plesk installed – with plesk it is easy to schedule your Cron Jobs.
I will show you now how to set up your Cron Job through plesk.
First of all navigate into your domain and on your domain dashboard click CronTab.
Secondly once you are inside your Crontab select the name of your FTP user. In this case it is “swimming”.
Next you should click on the Add Scheduled Task for FTP user from the tools menu at the top of the screen.
Now the important bit – what you should do is schedule the task for every 10 minutes. To do this we use the following command in the minutes section – */10. Next we want this to execute every hour of every day of every month – so we simply add a * to all the other boxes.
The last thing to do is to actually perform a command for this scheduled event. In our case on our plesk servers (should be reasonably similar for most linux server paths) we use the following command:
/usr/bin/php -f /var/www/vhosts/mydomain.com/httpdocs/cron.php
Simply replace mydomain.com with whatever your domain is called e.g. e-commercewebdesign.co.uk
Here is a screenshot to better demonstrate:
Once your cron job has been saved you will see that Magento will now run your scheduled tasks at the date/time you inputted (or 10minutes after the actual time).
Thanks for visiting our magento blog – I hope you found this post useful – any questions please let me know!
