I want to know how to set cron for reindexing a particular indexer method in Magento 2. I have used below code to reindex all but not working:

* * * * * php –f /shell/indexer.php reindexall

Can somebody help?

my cronjob

enter image description here

up vote 10 down vote accepted

You can launch reindex a separate index as independent process, like:

* * * * * /usr/bin/php /Users/uchuhlebov/web/m212/www/bin/magento indexer:reindex catalog_category_product >> /Users/uchuhlebov/web/m212/www/var/log/indexer.cron.log

Where:

  1. * * * * * - time
  2. /usr/bin/php - path to the php
  3. /Users/uchuhlebov/web/m212/www/bin/magento - path to your Magento CLI (/Users/uchuhlebov/web/m212/www/ - is Magento root dir)
  4. indexer:reindex catalog_category_product command you want to launch
  5. >> /Users/uchuhlebov/web/m212/www/var/log/indexer.cron.log - log output

In my example I launch reindex of the catalog_category_product index, but you can use any type. If you want to launch more than 1 reindex, you can specify them ( index name ) through the space.

Here you can find an answer for the question "How to get path of the php binary on server":

It's usually /usr/bin/php but you could try to capture and parse the output of the command 'whereis php' or 'which php''.

Or better yet, use the constant PHP_BINARY if it is available. Have a look here.

In addition check that your cron process is running: /etc/init.d/crond status should display something similar to crond (pid 1494) is running...

To view the list of available indexes use the command:

bin/magento indexer:info

Result:

design_config_grid                       Design Config Grid
customer_grid                            Customer Grid
catalog_category_product                 Category Products
catalog_product_category                 Product Categories
catalog_product_price                    Product Price
catalog_product_attribute                Product EAV
catalogsearch_fulltext                   Catalog Search
cataloginventory_stock                   Stock
catalogrule_rule                         Catalog Rule Product
catalogrule_product                      Catalog Product Rule
  • 1
    yet not working. Can my /usr/bin/php path be different on my server? or any solution? – Arshad Hussain Dec 8 '16 at 9:50
  • @ArshadHussain Yes. Please look for the answer here stackoverflow.com/questions/18656678/… – Siarhey Uchukhlebau Dec 8 '16 at 10:22
  • @ArshadHussain In addition check that your cron process is running: /etc/init.d/crond status should display something similar to crond (pid 1494) is running.... Please, look at my updated answer. – Siarhey Uchukhlebau Dec 8 '16 at 10:58
  • which php gives "/opt/bitnami/php/bin/php" and whereis php gives "php" – Arshad Hussain Dec 8 '16 at 11:05
  • @ArshadHussain try to use /opt/bitnami/php/bin/php in the cronjob – Siarhey Uchukhlebau Dec 8 '16 at 11:05
* * * * * /usr/bin/php /path/to/your/site/root/bin/magento index:reindex <index_type>
  • it is not working, is there any other keyword instead of "php"? – Arshad Hussain Dec 8 '16 at 9:35
  • 1
    You may need /usr/bin/php. – Paul Dec 8 '16 at 9:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.