Categories: How ToMagento 2

How to Set up Magento 2 Cron in Xampp for Windows

Cron jobs or scheduled tasks in Magento are enabled in order to perform some periodic operation on timely basis. Cron jobs need to be setup for following services and operations to work on specific date and time,

they are:

  • Re-indexing
  • Catalog price rules
  • Sending newsletters
  • Generating Google sitemaps
  • Customer notifications or alert messages
  • Auto update currency rates
  • Scheduled database log cleanups
  • Cache cleanups

In Magento 2, three cron jobs required to be run. As windows doesn’t have cron, we need to use a bat file and configure it to run as a scheduled task as shown below:

    1. First of all, find location of php.exe – Generally where Xampp is installed, it’s in Drive:\xampp\php e.g c:\xampp\php
    2. Go to a folder and create a file named mycron.bat
    3. Edit this file and paste 3 lines shown below:
php_path\php.exe magento_root\bin\magento cron:run
php_path\php.exe magento_root\update\cron.php
php_path\php.exe magento_root\bin\magento setup:cron:run

For example, mycron.bat looks as follows:
C:\xampp\php\php.exe C:\xampp\htdocs\magento\bin\magento cron:run
C:\xampp\php\php.exe C:\xampp\htdocs\magento\update\cron.php
C:\xampp\php\php.exe C:\xampp\htdocs\magento\bin\magento setup:cron:run

    1. Save the file, open command prompt and enter following command:
      schtasks /create /sc minute /mo 5 /tn Magento\Cron /tr path_t_bat_file\mycron.bat
    2. Now click on Start –> Control Panel –> Administrative Tools –> Task Scheduler.

  1. Expand Task Schedule Library from the left hand column and click Magento.
  2. Select Cron from the middle pane, click properties from the right pane under selected items.
  3. Under Security Options, click the Change User or Group button.
  4. Now in the current window, enter System username in the object name box and click check names. Click OK to close the User window, and OK to close the Cron properties Window, and close Task Scheduler.
  5. Cron job setup is successful and it will run every 5 minutes.

Let me know if you suffering from any issues while setting up cron. I’ll be there to fix it for you.

Click to rate this post!
[Total: 16 Average: 4.1]
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.🏏

View Comments

  • Hello,

    I have followed the steps mentioned above. I get a popup window once click OK after entering System username. It asks me to enter the Password for the same, which I do not know. Is there a way to find that out? If I leave the Password field blank it gives me an error saying: The following error was reported: This user can't sign in because this account is currently disabled.

    Can you please suggest what is wrong?

    I have set up a Magento 2 website via localhost (xampp).

    Thank you!

  • I have followed the steps you have mentioned. But I am asked to give password when click OK after Step 9. If I give the password, which is admin password, I get an error saying: " Task Scheduler cannot apply your changes. These user account is unknown, the password is incorrect, or the user account doesn't have permission to modify the task."
    Please let me know where I am going wrong. Am I supposed to create a new account?? I am confused.

    TIA!

  • hey,

    I'ts just opening mycron.php file in phpstorm thats all . So no update indexes

    here is my code in mycron.php file:

    C:\xampp\php\php.exe C:\xampp\htdocs\magento\bin\magento cron:run
    C:\xampp\php\php.exe C:\xampp\htdocs\magento\update\cron.php
    C:\xampp\php\php.exe C:\xampp\htdocs\magento\bin\magento setup:cron:run

  • Sorry Guys I might be doing something wrong
    Not quite sure what you mean by
    2) Go to a folder and create a file named mycron.bat
    Do we need to create mycron.bat in the php folder? or somewhere else?
    also after creating this you show a screenshot of runcron.bat (do we need to create this file also?) or it creates auto.
    I'm installing Magento2 on xampp

    • You need to create a file in your php folder like c:\xampp\php\mycron.bat

      That is the screenshot of the same file mycron.bat.
      Screenshot shows just example.

  • Thanks for the tutorial. However, when my task scheduler triggers the batch file, I get the following error prompt after the command window appears: "Windows cannot find 'php'. Make sure you typed the name correctly and then try again." I click ok on the error message and here is what appears in the command window afterwards. Eventually the other 2 commands in the batch file execute without issue on their own. Using Xampp with windows10, Any Thoughts?:

    C:\WINDOWS\system32>C:\xampp\php\php.exe C:\xampp\htdocs\magento2\bin\magento cron:run
    [Magento\Framework\Exception\LocalizedException]
    Command returned non-zero exit code:
    `start /B "magento background task" php "C:\xampp\htdocs\magento2/bin/magento" cron:run --group=index --bootstrap=s
    tandaloneProcessStarted=1 2>&1`
    [Exception]
    The system cannot find the file php.
    cron:run [--group="..."] [--bootstrap="..."]

  • Hello sir, thanks for this. But i still got problem while i am installing through web portal in admin panel. i am using xampp localhost.

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