Magento re-index via command line

Posted by Damodar Bashyal on December 29, 2014

 

Magento re-indexing through command line

If you are hosting your Magento store on shared hosting, this is almost required that you have to run re-index through command line. Even if you are on powerful server, you may find from time to time reindex times out if you have big data.

To over come this issue, you can use your command line to run reindex on required indexes.

I use PuTTY to connect to server and then go to your magento install and then to shell folder. e.g.

~/public_html/shell

Here you can check status of current indexes with this command:

php indexer.php --status

That will print something like this.

Category Flat Data:                 Pending
Product Flat Data:                  Pending
Stock Status:                       Pending
Catalog product price:              Pending
Category URL Rewrites:              Pending
Product URL Rewrites:               Pending
URL Redirects:                      Pending
Catalog Category/Product Index:     Running
Catalog Search Index:               Pending
Tag Aggregation Data:               Pending
Product Attributes:                 Pending

Note: depending on magento version and custom extensions installed, you can have few different indexes too.

Now this command will help you to re-index all indexes through command line:

php indexer.php reindexall
// or
php indexer.php --reindexall
// or
php indexer.php --reindex all

To check available indexes you can run this command:

php indexer.php info

That will print:

catalog_category_flat         Category Flat Data
catalog_product_flat          Product Flat Data
cataloginventory_stock        Stock Status
catalog_product_price         Catalog product price
catalog_url_category          Category URL Rewrites
catalog_url_product           Product URL Rewrites
url_redirect                  URL Redirects
catalog_category_product      Catalog Category/Product Index
catalogsearch_fulltext        Catalog Search Index
tag_summary                   Tag Aggregation Data
catalog_product_attribute     Product Attributes

To check allowed usages run this command:

php indexer.php help

This will print:

--status <indexer>            Show Indexer(s) Status
--mode <indexer>              Show Indexer(s) Index Mode
--mode-realtime <indexer>     Set index mode type "Update on Save"
--mode-manual <indexer>       Set index mode type "Manual Update"
--reindex <indexer>           Reindex Data
info                             Show allowed indexers
reindexall                       Reindex Data by all indexers
help                             This help

If you need to reindex individual index, then you can run this command:

php indexer.php --reindex catalog_product_attribute

You can run multiple indexes at once by separating them by comma.

php indexer.php --reindex catalog_product_attribute,catalog_product_flat,catalog_product_price

You can also check current index modes of all indexes with this command:

php indexer.php --mode

That will print something like this:

Category Flat Data:                 unknown
Product Flat Data:                  unknown
Stock Status:                       unknown
Catalog product price:              unknown
Category URL Rewrites:              unknown
Product URL Rewrites:               unknown
URL Redirects:                      unknown
Catalog Category/Product Index:     unknown
Catalog Search Index:               unknown
Tag Aggregation Data:               Update on Save
Product Attributes:                 Update on Save

Reference: shell/indexer.php

 
not published on website


QR Code: Magento re-index via command line