28 Feb Setting up a Magento 2 cron job in Plesk
If you’ve ever used Magento before you will know that many tasks are controlled by the cron job system, it’s essential for your Magento shop to function correctly. Magento 2 again uses cron jobs to activate many features, including reindexing data which previously you could do with a click of a button in the index management.
What is a cron job? In simple terms it’s a set of automatic scheduled tasks that will be performed at set times during the day, week, month or year. It’s a pretty handy way for your website to manage data efficiently, it would be impossible to manually perform these tasks on a regular basis.
Here are some of the key tasks that your cron job will schedule and perform:
- Update of currency rates
- Magento emails
- Customers alerts and notifications
- Generating Google sitemaps
- Catalog price rules
Generally the normal way to setup a cron job on a UNIX server would be to configure a crontab using SSH and commands, but if you’re like me then this can be a little tricky and scary. Thankfully Plesk provides us with a user friendly interface for doing the same thing, it’s just a case of knowing the right information to put in.
In Plesk you need to navigate to your subscription for the Magento website, in the website and domain settings you should see the Scheduled Tasks option. I think the exact location of this can change depending on which version of Plesk you’re running, once you’ve located it select to add a new task. From here enter the following settings:
1. Task Type: Run a PHP script.
2. Script Path: Enter httpdocs/bin/magento in the first box and then enter cron:run in the argument box.
3. Run: Select Cron Style from the drop down and then enter */5 * * * * in the text box. (This is set to run the cron job every 5 minutes, you can change to any time you prefer)
4. Notify: You can set an email address to notify if the cron job was successful or not.
Save this task and the cron job should now be active, there’s an option to Run Now which will give you an instant notification of the results.
*NOTE: If you have your Magento installed in a different folder you will have to update your path accordingly.
Below you can see a screen shot of my settings:
For different schedule times other than 5 minutes you will need to research UNIX crontab formats, but I think you wouldn’t ever want it to be longer than 10 or 15 minutes as the cron job also processes things like order confirmation emails. Your customers might find it pretty annoying or maybe even worrying if they don’t receive these emails fairly quickly after purchasing from your online shop.
I’m sure there are very similar ways to setup scheduled tasks with other server applcations such as WHM, unfortunately I don’t have guides for them but the paths required for the settings should be exactly the same.