Setup the Cronjob
Setup the Cronjob in Magento 2
Magento 2 relies heavily on cronjobs to run essential background tasks. From reindexing and sitemap generation to sending automated emails and updating product feeds, cronjobs keep your store running smoothly. Setting them up correctly is crucial for both performance and stability.
Why Cronjobs Are Important in Magento 2
- Indexing – keeps your catalog, prices, and search results up to date.
- Caching – refreshes cache and improves store performance.
- Emails & Reports – automates sending newsletters, order confirmations, and reports.
- Feed generation – updates and exports product feeds (e.g., Google Shopping feeds).
- System tasks – clears logs, archives orders, and manages cleanups.
How to Setup the Cronjob in Magento 2
You can set up the Magento 2 cronjob in just a few steps. Make sure you have SSH access to your server.
1. Switch to the Magento File System Owner
su - magento_user
cd /var/www/html/magento2
2. Run the Magento Cron Command
Magento includes a handy script to automatically create the right cronjobs:
php bin/magento cron:install
This will add the required cronjob entries to the crontab of your Magento user.
3. Verify the Cron Setup
crontab -l
You should see something like:
* * * * * php /var/www/html/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
4. Test the Cronjob
You can manually trigger the cronjob to check if everything works:
php bin/magento cron:run
Troubleshooting
Cronjob is not running?
- Make sure the cron service is active on your server:
systemctl status cron
(Ubuntu/Debian) orservice crond status
(CentOS). - Check file permissions for the Magento user – cronjobs must run as the Magento filesystem owner.
- Review the cron log in
var/log/magento.cron.log
for errors.
Multiple stores and environments?
Each Magento environment (production, staging, development) should have its own cron setup to avoid conflicts.
Conclusion
Correctly setting up cronjobs is essential for running Magento 2 smoothly. Without them, important processes like indexing, caching, and feed generation won’t work as expected. Once configured, cronjobs run automatically in the background, saving time and ensuring your webshop stays up to date.
Need cronjobs for product feeds? Our Google Shopping Feed plugin fully supports automatic feed generation and uploads via Magento cronjobs.