Wondering how to run cron job manually in Magento 2? We can help you.
Here at Bobcares, we often handle requests regarding Magento as a part of our Server Management Services.
Today let’s see how our Support Engineers do this for our customers.
How to run cron job manually in Magento 2?
One of the most distinguishing features of Magento 2 is cron job.
Several Magento features require at least one cron job, which schedules activities to occur in the future.
The cron job will create a command or a script that is appropriate with the task you want to do.
Create the Commerce crontab
The Magento crontab is the configuration used to run Magento cron jobs.
Magento uses cron tasks that can run with different configurations.
The PHP command-line configuration controls the general cron job that reindexes indexers, generates e-mails, generates the sitemap, and so on.
Starting with version 2.2, Commerce creates a crontab for you.
We add the Commerce crontab to any configured crontab for the Commerce file system owner.
The Commerce crontab is inside #~ MAGENTO START
and #~ MAGENTO END
comments in your crontab.
To create the Commerce crontab:
- Firstly, log in as, or switch to, the Magento file system owner.
- Then, change to your Magento installation directory.
- Finally, enter the following command:
bin/magento cron:install [–force]
Use --force
to rewrite an existing Magento crontab.
Note:
magento cron:install
does not rewrite an existing crontab inside#~ MAGENTO START
and#~ MAGENTO END
comments in your crontab.magento cron:install --force
has no effect on any cron jobs outside the Magento comments.
To view the crontab, enter the following command as the Magento file system owner:
crontab -l
Run Cron From The Command Line in Magento 2
Make sure you run cron as a user with permission to write to the Magento file system.
The following syntax is used to run cron from the command line
Command options:
bin/magento cron:run [--group=""]
where --group
specifies the cron group to run (omit this option to run cron for all groups)
To run the indexing cron job, enter:
bin/magento cron:run --group index
bin/magento cron:run --group default
Remove the Magento crontab
To remove the Magento crontab:
- Firstly, log in as or switch to the Magento file system owner.
- Then, change to the Magento installation directory.
- Finally, enter the following command:
bin/magento cron:remove
[Need assistance with Magento? – We can help you]
Conclusion
In short, Cron Job is one of the important features of Magento.Today, we saw how our support techs run cron job manually in Magento 2.
0 Comments