Magento 2: How to set cron for reindex in SSH in magento 2?

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

* * * * * /usr/bin/php /path/to/your/site/root/bin/magento index:reindex <index_type>