Categories: Magento Tutorials

How to Setup Cron Job Magento 2: Magento 2.4 updated

Hello, Magento Folks!

In order to spontaneously execute several operations in your Magento 2 site, setting up cron jobs in Magento 2 is required as it schedules tasks in line. These operations can be automatically performed through the script written in the configuration. 

Cron Job – one of the best ways to periodically manage your programs automatically and properly rather than doing it manually. Just ensure setting the base URL correctly so that when the cron is running, it executes operations just perfectly.

Setup Cron Job from Magento 2 Admin Panel

  • Log in to the Magento 2 backend panel. From the left panel, go to Stores > Settings > Configuration.
  • Navigate to Advanced > System and expand the Cron (Scheduled Tasks) section and perform further on the Cron configuration options for group: index and Cron configuration options for group: default sections.

Set the values of Cron configuration options for group: index as the following image:

Set the values of Cron configuration options for group: default as the following image:

  • On finishing, Save Config.

Setup Magento 2 Cron job by command line

Steps to Create the crontab :

First, Open the Terminal and log in with the root user. After that go to Magento Root Path then run the below command:

bin/magento cron:install

Output:

Crontab is created and saved.

bin/magento cron:install --force

Crontab is created and saved

NOTE: Use –force to rewrite an existing Magento crontab.

  • magento cron:install does not rewrite an existing crontab inside #~ MAGENTO START and #~ MAGENTO END comments in crontab.
  • magento cron:install –force does not affect any cron jobs outside Magento comments.

To check crontab List, run the below command:

crontab -l

Output:

Steps to Run cron from the command line

Log in with the root user in the terminal. Go to Magento Root Path After running the below command:

bin/magento cron:run

Output:

Ran jobs by schedule.

where –group defines the cron group to run (eliminate this alternative if you want to run cron for all groups)

bin/magento cron:run [--group="<cron group name>"]

To run the indexing cron job, enter:

bin/magento cron:run --group index

To run the default cron job, enter:

bin/magento cron:run --group default

Steps to Remove the Magento crontab:

First Open Terminal and login with the root user and go to Magento Root Path After running the below command :

bin/magento cron:remove

Output:

Magento cron tasks have been removed

Bottom Line

We hope that setting up cron through the Magento backend panel and the command line was helpful to you. Still, if you meet any conflicts, you can catch us here. we would be pleased to assist you.

Read the similar blog – How to Set Up Cron Jobs in Magento 2

Happy Reading!

Click to rate this post!
[Total: 6 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

2 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

6 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago