PHP Magento Tips

Reindex Magento Via Command Line Shell Script

Rate this posting:
{[['']]}

You can run reindex process very easily from Magento backend under system -> Index management.

But If you are hosting your Magento store on shared hosting, then sometime it is 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 tool to run reindex on required indexes.you can use PuTTY to connect to server and then go to your Magento install and then to shell folder to run re-indexing command.

$ cd magento/shell

Here you can check status of current indexes with this command:
$ php indexer.php --status


Product Attributes:                 Pending

Product Prices:                     Pending

Catalog URL Rewrites:               Pending

Category Products:                  Pending

Catalog Search Index:               Pending

Stock Status:                       Pending

Tag Aggregation Data:               Pending

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

To check available indexes you can run this command:

$ php indexer.php info



catalog_product_attribute     Product Attributes

catalog_product_price         Product Prices

catalog_url                   Catalog URL Rewrites

catalog_category_product      Category Products

catalogsearch_fulltext        Catalog Search Index

cataloginventory_stock        Stock Status

tag_summary                   Tag Aggregation Data

To check allowed usages run this command:

$ php indexer.php help


Usage:  php -f indexer.php -- [options]


  --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


  <indexer>     Comma separated indexer codes or value "all" for all indexers

If you need to reindex individual index, then you can run this command:
$ php indexer.php --reindex catalog_product_attribute

Product Attributes index was rebuilt successfully in 00:00:07

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

Product Attributes index was rebuilt successfully in 00:00:05
Product Flat Data index was rebuilt successfully in 00:01:43
Product Prices index was rebuilt successfully in 00:00:05

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

Product Attributes index was rebuilt successfully in 00:00:02
Product Prices index was rebuilt successfully in 00:00:04
Catalog URL Rewrites index was rebuilt successfully in 00:02:02
Category Products index was rebuilt successfully in 00:00:07
Catalog Search Index index was rebuilt successfully in 00:00:38
Stock Status index was rebuilt successfully in 00:00:00
Tag Aggregation Data index was rebuilt successfully in 00:00:01

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

$ php indexer.php --mode

Product Attributes:                 Update on Save
Product Prices:                     Update on Save
Catalog URL Rewrites:               Update on Save
Category Products:                  Update on Save
Catalog Search Index:               Update on Save
Stock Status:                       Update on Save
Tag Aggregation Data:               Update on Save

You can also set the indexer to "Manual Update" mode which will prevent it from automatically indexing on save/edit/delete.

//this will put 'Catalog URL Rewrites' index in 'Manual Update' Mode.
$ php indexer.php --mode-manual catalog_url
Catalog URL Rewrites index was successfully changed index mode

//this will put 'Catalog URL Rewrites' index back to 'Update on Save' Mode.
$ php indexer.php --mode-realtime catalog_url
Catalog URL Rewrites index was successfully changed index mode
Tag : Caching, Magento
0 Comments On "Reindex Magento Via Command Line Shell Script"

Back To Top