How to Reindex Magento Indexes via SSH

By default in Magento, we can reindex all the Magento data through Admin Panel using the below the path, Magento Admin Side > System > Index Management

How to Reindex Magento Indexes via SSH

How to Reindex Magento Indexes via SSH

here we can select the indexes and reindex them. However, sometimes the reindexing process times out and does not complete through the web interface.

Fortunately, there is another faster way to reindex Magento indexes.

Reindex Magento Indexes via SSH

If you have the SSH access to your server, log in to your account via SSH, go to your Magento installation directory and execute the following command to reindex:

Command to view a list of available indexes in Magento:

php shell/indexer.php -info

Command to reindex all indexes:

php shell/indexer.php -reindexall

Command to reindex individual indexes:

php shell/indexer.php -reindex catalog_product_attribute

php shell/indexer.php -reindex catalogsearch_fulltext

php shell/indexer.php -reindex catalog_category_flat

php shell/indexer.php -reindex catalog_product_flat

php shell/indexer.php -reindex cataloginventory_stock

php shell/indexer.php -reindex catalog_category_product

php shell/indexer.php -reindex catalog_product_price

php shell/indexer.php -reindex tag_summary

php shell/indexer.php -reindex catalog_url

Reindex Magento Indexes via PHP code

Using the below PHP script, we can reindex all the Magento data.

<?php
    /* @var $indexCollection Mage_Index_Model_Resource_Process_Collection */
    $indexCollection = Mage::getModel('index/process')->getCollection();
    foreach ($indexCollection as $index) {
        /* @var $index Mage_Index_Model_Process */
        $index->reindexAll();
    }

If you want to reindex any particular index, you could use the code below that runs based on the given process code

<?php
    $process = Mage::getModel('index/indexer')->getProcessByCode( 'catalog_product_price' );
    $process->reindexAll();

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *