How to configure Magento cron job How to configure Magento cron job

Cron job is an important component for correct Magento performance. It is widely used for running actions that are performed on schedule, such as indexing and caching, email dispatches, sitemap generation, currency rates updates, and many more actions as well.

Today we would like to explain how to configure Magento cron job correctly. The configuration process can vary a bit depending on your site’s control panel (cPanel, Plesk, etc).

How often should you run cron executions for Magento?

Our recommendation is to run cron every 5 minutes. We have seen various recommendations, from once in an hour to once a minute, but once in every 5 minutes from our experience is a right choice for a typical middle-sized Magento shop. If you set up cron job for running every 5 minutes and use SSH, the part of the command which is responsible for the schedule will look like this:

*/5 * * * *

Commands to run cron in Magento

The commands used to run cron are different for various Magento versions.

MAGENTO 1.X
1
sh /path/to/your/magento/site/root/cron.sh
MAGENTO 2.X
1
php /path/to/your/magento/site/root/bin/magento -- --quiet cron:run

Do not forget to change /path/to/your/magento/site/root to the path of your website’s default folder. Magento 1.x has the option to run cron via your site URL, but we don’t recommend doing this. Such method causes issues with running several simultaneous cron processes, which can also be followed with server performance troubles and task completion failures.

Adding a new Magento cron task via SSH

Log in to the server via SSH. Run crontab -e command to add a cron task. At this point you will see a text editor, where you can add or edit cron tasks. Starting from a new line, add the following record:

1
*/5 * * * * sh /path/to/your/magento/site/root/cron.sh

Again, don’t forget to insert your own default folder path!

Save the changes and close the file. If you did everything correctly, crontab -l command will show you the newly created task.

Adding a new Magento cron task via cPanel

To set up a new cron task in Magento via cPanel, log into your site’s configuration panel at

http://yourmagentosite.com:2082/ or https://yourmagentosite.com:2083/.

Then, enter cron into the search field, and you’ll see a Cron jobs option in the Advanced section.

Find cron settings in cPanel

To set up a cron job with this method, you may need to enter an email address in the Cron emailsection. This email will be used to send cron messages to, which is useful in case of any cron job execution issues.

Setup cron email in cPanel for Magento

Now let’s set the cron schedule and the command to be run.

Add cron job in Magento via cPanel

Press Add New Cron Job to finish your configuration.

Check Magento cron status

To make sure that your cron task works correctly, you can go and see over the changes that appear in the cron_schedule table of the Magento database. If its contents are changing, then you configured cron in the right away.

NB: Do not manually change anything in this database table! At this point everything you should do is watch.

Here’s the example. We opened the table:

Check Magento cron

Click here to read the full article!

 

No comments so far.

Be first to leave comment below.

Your email address will not be published. Required fields are marked *