Cronjob Setup for Magento 2 Guide
Magento 2 relies heavily on cron jobs for background tasks. Without properly configured cron, many features won't work - including email sending, indexing, feed generation, and most third-party extensions. This guide helps you set up and verify cron is running correctly.
Why Cron Matters
Cron handles critical background tasks:
- Indexing - Keeps catalog, prices, and search data current
- Email queue - Sends order confirmations, newsletters, notifications
- Feed generation - Creates product feeds for Google Shopping, marketplaces
- Order processing - Imports orders from channels like Channable, Bol.com
- Cache management - Cleans expired cache entries
- Log cleanup - Manages log file sizes
- Scheduled imports/exports - Runs data transfers
If your Magento store has issues with any of these, cron misconfiguration is often the cause.
Quick Setup
1. Navigate to Magento Directory
cd /var/www/html/magento2
Replace with your actual Magento installation path.
2. Install Cron Jobs
Run as the web server user (often www-data, apache, or magento):
bin/magento cron:install
This automatically adds the required entries to crontab.
3. Verify Installation
Check that cron entries were added:
crontab -l
You should see entries like:
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log
Manual Cron Test
Run cron manually to verify it works:
bin/magento cron:run
If successful, you'll see output about scheduled jobs being processed.
Check Cron Status in Admin
Go to System → Cron Schedule (if available) or check the cron_schedule database table:
SELECT * FROM cron_schedule ORDER BY scheduled_at DESC LIMIT 20;
Healthy cron shows jobs with status = 'success' and recent executed_at timestamps.
Troubleshooting
Cron Not Running
Check cron service is active:
# Debian/Ubuntu
systemctl status cron
# CentOS/RHEL
systemctl status crond
Check Magento cron log:
tail -100 var/log/magento.cron.log
Check system cron log:
# Debian/Ubuntu
tail -100 /var/log/syslog | grep CRON
# CentOS/RHEL
tail -100 /var/log/cron
Permission Issues
Ensure the web server user owns the crontab:
# Check current user's crontab
crontab -l
# If needed, install as specific user
sudo -u www-data bin/magento cron:install
PHP Path Issues
If cron jobs fail, the PHP path might be wrong. Find your PHP binary:
which php
Then manually edit crontab if needed:
crontab -e
Jobs Stuck in "pending" or "running"
Clear stuck jobs:
bin/magento cron:remove
bin/magento cron:install
Or directly in database:
DELETE FROM cron_schedule WHERE status = 'pending';
DELETE FROM cron_schedule WHERE status = 'running';
Memory Errors
If cron jobs fail with memory errors, increase PHP CLI memory in php.ini or create a wrapper script:
#!/bin/bash
/usr/bin/php -d memory_limit=2G /var/www/html/magento2/bin/magento cron:run
Multi-Environment Setup
For staging and production environments, ensure each has its own cron configuration. Don't share crontabs between environments - this causes conflicts and duplicate processing.
Removing Cron Jobs
To uninstall Magento cron entries:
bin/magento cron:remove
Need More Help?
Documentation:
- All Help Articles - Complete documentation overview
Support:
- Contact Support - Get help from our team