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:
-
- First of all, find location of php.exe – Generally where Xampp is installed, it’s in Drive:\xampp\php e.g c:\xampp\php
- Go to a folder and create a file named mycron.bat
- 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
-
- 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
- Now click on Start –> Control Panel –> Administrative Tools –> Task Scheduler.
- Save the file, open command prompt and enter following command:
- Expand Task Schedule Library from the left hand column and click Magento.
- Select Cron from the middle pane, click properties from the right pane under selected items.
- Under Security Options, click the Change User or Group button.
- 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.
- 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.
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
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,
Thanks! Well explained!
Thanks!
Luego de haber realizado los pasos, aun me genera problemas cron
Thanks
thank you! please can explain the bash file and the command to run it. thank you again
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.
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=”…”]
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.
I have setup cron , but cron job not running after 5 min . Can you tell me the reason
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
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!
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!