When working with Magento 2 in backend, sometimes you will see the system message “one or more indexers are invalid. Make sure your magento cron job is running.”
The error message will be displayed in Magento 2 backend like this:
In this tutorial, I will describe the cause of this issue and solutions to fix it.
What is Magento 2 indexers
As you may know, Magento 2 has a very complicated database structure, there are a lot of data in database such as: Catalog, prices, users, store, storeviews…
When you make changes to your Magento 2 store, Magento 2 system will start the indexing process to update changes to the website’s database. The indexing process will distribute data to the special tables to improve your store’s performance.
Cause of the issue
Sometimes, this is just a normal notification from Magento 2 system to indicate that your store needs to be reindexed to update information.
There may be another cause of this issue that is related to cronjob on your server. By default, the reindex process happens automatically on your server if cronjobs are set properly. If there is anything wrong with your cronjobs and the reindex process does not start automatically => you will have to start the reindex process manually
To resolve this issue, we will check the reindex mode that is currently set and run the reindex command. We will also check if cron jobs for Magento 2 are working properly
Setting the reindex mode in Magento 2 backend
In Magento 2 admin dashboard, go to System > Index management
Select the Indexer you want to reindex, or you can select all if you don’t know what to be reindexed
In Action dropdown menu, select the action you want to apply to the selected indexers
There are 3 types of action we can apply to select indexers:
- Update on Save: Reindex automatically when the data is updated (must use custom code to trigger reindexing)
- Update by Schedule: index tables are updated by Cron jobs by the configured schedule. Note: does not support the
customer_gridindexer, you can’t reindex this indexer using this method.
- Invalidate index: Disable the selected indexer
Run the reindex command
To see the list of all indexers in Magento 2, use this command
php bin/magento indexer:info
The following command will reindex all the indexers in Magento 2
php bin/magento indexer:reindex
If you wish to reindex only a specific indexer, use this command
bin/magento indexer:reindex [indexer]
For example, I want to reindex only
catalog_category_product => the syntax is
bin/magento indexer:reindex catalog_category_product
Check and run cronjob
By default, Magento 2 create Cron jobs as follow to reindex indexer
#~ MAGENTO START * * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run | 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 #~ MAGENTO END
You can check if these cron jobs were added to your crobtab using this command:
If the cron jobs for Magento 2 is missing, we will need to reinstall them using this command:
php bin/magento cron:install
To start running all Magento 2 cronjobs use this command:
php bin/magento cron:run
Now go to Magento 2 admin dashboard and go to index management section, you will see that all indexers status are Ready.
If you are not familiar working with cron, you can ask for your hosting provider’s support and send them the cronjobs above. The support staff will add these lines to your crontab for you. For the list of good Managed Magento 2 hosting providers, check this article
Refresh admin dashboard and the notification message “one or more indexers are invalid. Make sure your magento cron job is running” should be resolved
In Magento 2, the index system is very crucial. It’s one of the most important core features of Magento 2 that help improve the store’s performance.
I hope the tutorial help you resolve the issue and if you have any problem or suggestuion, feel free to drop a comment below. I will be happy to help!