How to Set up Magento 2 Cron in Xampp for Windows

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
cron-commands

    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.

process-set-up-magento-2-cron-in-xampp-for-windows

  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.

Previous Article

How to Upgrade Magento 2.x to the Latest Version

Next Article

How to Enable Template Path Hints in Magento 2

Write a Comment
  1. Hello,

    Thanks for this, however i have followed your steps to the letter (Apart from file locations) and I cannot reindex my magento 2.

    Please advise

    1. Check your task scheduler is working properly or not,
      Check all the given configuration given in the blog, it should work, We have set up this to upgrade Magento version in local xampp,

  2. thank you! please can explain the bash file and the command to run it. thank you again

  3. 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.

  4. 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=”…”]

  5. 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

    1. 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.

  6. Youri adriaensens

    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

  7. 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!

  8. 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!

Leave a Comment

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

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨