# Setting up Magento cron jobs on managed hosting

> Set up the cron jobs Magento needs for reindexing, emails, sitemaps and price rules, for Magento 2 and older Magento 1.9 stores.

Source: https://helpcenter.ruachost.com/apps/magento/setting-up-magento-cron-jobs-on-managed-hosting/

Magento relies heavily on **cron jobs** to automate essential tasks such as reindexing, sending newsletters, generating sitemaps, and applying catalog price rules. On **ruachost.com  managed hosting**, you must configure cron jobs correctly to ensure smooth store operation.

## Why Cron Jobs Are Important

- Automates background tasks (indexing, cache cleaning, scheduled emails).
- Keeps catalog price rules and promotions updated.
- Ensures reports, alerts, and feeds are generated on time.
- Prevents performance issues caused by manual task execution.

## Configuring Cron Jobs in Magento 2

1. **Log in to cPanel** on your managed hosting account.
2. Go to **Advanced → Cron Jobs**.
3. Delete the default cron job created by Softaculous (if present):

   ```bash
   12,18,33,54 * * * * php /home/username/public_html/bin/magento cron:run > /dev/null
   ```

   *(Replace* `username` *with your hosting account username.)*
4. Add the following new cron jobs (set to run every 15 minutes):

   ### Magento main cron job

   ```bash
   */15 * * * * /usr/local/bin/php /home/username/public_html/bin/magento cron:run | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' 2>&1 > ~/magento_cron.log
   ```

   ### Magento update cron job

   ```
   */15 * * * * /usr/local/bin/php /home/username/public_html/update/cron.php | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' 2>&1 >> ~/magento_cron.log
   ```

   ### Magento setup cron job

   ```
   */15 * * * * /usr/local/bin/php /home/username/public_html/bin/magento setup:cron:run | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' 2>&1 >> ~/magento_cron.log
   ```
5. Save the cron jobs.
6. Verify that output and error messages are logged in `~/magento_cron.log`.

## Configuring Cron Jobs in Magento 1.9 and Older

1. Log in to Magento Admin.
2. Go to **System → Configuration → Advanced → System → Cron (Scheduled Tasks)**.
3. Set the following values:

   - **Generate Schedules Every** → 1
   - **Schedule Ahead for** → 1
   - **Missed if Not Run Within** → 30
   - **History Cleanup Every** → 120
   - **Success History Lifetime** → 120
   - **Failure History Lifetime** → 120
4. Save configuration.
5. In cPanel, set a cron job to run every 4 hours:

   ```
   0 */4 * * * php /home/username/public_html/cron.php
   ```

## Important Notes

- Magento is resource‑intensive; cron jobs should not run more frequently than every 15 minutes on managed hosting.
- Always replace `username` with your actual hosting account username.
- Logs are stored in `~/magento_cron.log` for troubleshooting.
- If cron jobs fail, check PHP paths and permissions.
