Tips, Tutorials, Resources for Web Design and Online Marketing

Main Menu

  • Mobile App Development
    • App Tutorials
    • App Reviews
  • Website Guides
  • SMBs & Startups
  • News
  • Guest Posts
  • About
    • Mobile App Development Company Delhi, India
    • Mobile App Development Company Gurgaon
    • Mobile App Development Company Dallas, Florida
    • Website Design Company Delhi
    • WordPress Website Development Company

Tips, Tutorials, Resources for Web Design and Online Marketing

Header Banner

Tips, Tutorials, Resources for Web Design and Online Marketing

  • Mobile App Development
    • App Tutorials
    • App Reviews
  • Website Guides
  • SMBs & Startups
  • News
  • Guest Posts
  • About
    • Mobile App Development Company Delhi, India
    • Mobile App Development Company Gurgaon
    • Mobile App Development Company Dallas, Florida
    • Website Design Company Delhi
    • WordPress Website Development Company
  • 10 Tips To Grow Your Online Business

  • How to Choose the best custom software development companies in India ?

  • 7 Tasks to Complete before Starting Your Website Development Project

  • Online Marketing Tips and Productivity Tools for Small Businesses during Coronavirus

  • Tutorial 2: Which type of website does your business need ?

Small Businesses & StartupsWeb
Home›Small Businesses & Startups›How and Why to do Magento Reindexing using CLI and Crontab in Magento 2 ?

How and Why to do Magento Reindexing using CLI and Crontab in Magento 2 ?

By Umesh Sethi
March 12, 2019
6890
0

If you are a Developer working on Magento, especially for Magento 2, one small recurring headache would probably be the Magento Reindexing requirement.

Yes, ‘Reindexing‘ .. that cruel word which requires you to go to Command Line Interface on a terminal such as Putty and write in some stuff, then empty the cache etc. Starting from Magento 2, you cannot do Reindexing through the Admin Panel (unless of-course you install some extension , which may well be bloated).

Essentially for Magento 2, such as Magento 2.1, 2.2, there are two most common method for Re-indexing. But before we come to that, let’s look at why and when we need to reindex.

Why art thou always reindexing, O Magento ?
Magento stores a lot of product , user, category, pricing, product attributes data etc. in many database tables. To optimize web store performance, Magento has to transform data into special tables using indexers.
For example, if you change the price of your product – say from $29.99 to $24.99 or if you add new products, Magento would need to reindex to display this data to the user browsing your store.

Without indexing, Magento would have to calculate the price of every product on the fly—taking into account shopping cart price rules, bundle pricing, discounts, tier pricing, and so on. Similarly for products within subcategories or inventory calculations. Imagine this happening on a store with hundreds and thousands of products on each page load. Indexing allows Magento to store this data in quick loading way with most of the calculations already built in.

So, lets talk about how you can do Reindexing in Magento. We will be talking specifically about Magento 2. In Magento 2, there are essentially 2 options for re-indexing:

1. Manual Reindexing from CLI using a Terminal like Putty

Here the steps are:
a) First to download a SSH terminal like Putty
b) Get SSH access
c) Generate private key etc. with help from your host and add it to the local computer.
d) Login to Putty with the passphrase provided by your host and using the correct port and type in the correct commands which are:
Code:php bin/magento indexer:reindex [indexer]

Omit the [indexer] switch to reindex all indexes which is what you will generally do on the smaller to medium sites. Note that this is a manual one time re-index. If your website gets product updates, price changes, inventory changes etc. regularly and maybe multiple times during the day you need to do a CRON JOB REINDEX, which is the 2nd option.
Note: The above command assumes you are in the magento root directory which is most likely the directory in which your magento website is installed.

2) Running a Cron job to Reindex your Magento 2 website

In the Index Management page where your index status are shown, there is a Mode option. This should be set to ‘Update on Schedule’. for Cron.
Now, to run a Cron Job on a shared hosting for magento reindex, you will probably find cpanel having a specific cron section and there in you have the option of adding cron job like shown.

cron options for magento screen

According to the Magento 2 development docs – below are the cron options that one can run. When running a cron job , you will have the option to choose how Often you want to run it and what the command is. Here are the 3 set of commands that typically are used for running cron job. The first one is the one used for managing indexes. The other two are for deploying components and maintaining Magento upgrade. You probably shouldn’t be running the last 2 as cron jobs as these are not the very regular changes to be applied to your Magento 2 site and should be done in managed manual way.


* * * * * 'path to php binary' 'magento install dir'/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/log/magento.cron.log
* * * * * 'path to php binary' 'magento install dir'/update/cron.php >> /var/log/update.cron.log
* * * * * 'path to php binary' 'magento install dir'/bin/magento setup:cron:run >> /var/log/setup.cron.log

Note the following:
a) You need to specify the directory / path to php binary. In case you do not know this; do not hesitate to talk to your Hosting support guys and they will tell this to you immediately. But let’s come to another important issue – the structuring of the command.

b) There are two parts of the command, where the first one runs the command, the second is asking to update the log file with the result.

c) The ‘path to php binary’ and ‘magento install dir’ has to be replaced by the respective paths. This you can find from your host and the magento install directory is typically something like /var/www/html/magento2 . Ofcourse this depends from host to host. Similarly php bin directory is something like /usr/bin/php

There is also a 3rd option and this one is for many of those who are not the biggest fans of using CLI for performing various tasks.

3) Reindex your Magento 2 installation from Admin Panel using Plugins – many of which are Free .

Yes this is a good option as well if you are not comfortable with CLI or running cron jobs. An example of a Free extension to Re-index from Admin panel for Magento 2 is this BSS Commerce Extension. This should be downloaded from the marketplace and installed as per the guideline. Using this extension you will be able to index directly on the Index Management page in your Admin panel of Magento.

magento 2 reindex from admin extension

Image Courtesy: BSSCommerce Marketplace Extension

What about Magento 1 Installations?
Note that before Magento 2, you could well reindex easily through your Magento Admin Panel in an ad-hoc manner. But that changed with the new version.

Thankfully, Magento atleast tells us that ‘One or more of your indexes is invalid’even in Magento 2 through the Status column. And ofcourse if you are using Cron job, you can also log the result in log files (in Var/log directory).

One big problem – CLI based Magento Reindexing does not work for Magento 2.2 on Php 7.2 / 7.2+ environments.

Yes, if you are hosted on a server which has Php 7.2 environment which many of the new shared hosting default to – you may be experiencing issue of your CLI based reindex etc. commands not working. Like the figure below:

putty magento error on reindexing
In some cases you can change the php configuration of your server to 7.0 which should make it work but considering it is a shared host you may not be able to. And it is quite possible, the terminal root php environment would not change.

As you can see, we are unable to reindex from the command line and the environment is 7.2 . The dreaded error we get is : The each() function is deprecated. This message will be supressed further… ON Magento 2 , php 7.2. File name : vendor/collinmollenhour/cache-backend-file/File.php

So here is what we suggest as a solution:

A) First try changing the environment to 7.0 from Control panel – assuming you don’t have other sites which require it. Now in terminal , in the specific directory, type php -v . This will show you the current environment after the change. If it is still not 7.0 , then you probably won’t get the right to change this if this is a shared hosting.

So what is the next step. From experience and scouring through the various solutions available on the internet, we came to realize there are basically three solutions.

1. The first is to edit the 2 files (thankfully only 2) which cause the error and change the lines of code as explained here (at the very end). Here we are editing two files both in vendors folder which are deprecated in Php 7.2 and hence cause the issues. This is not a very neat solution and only recommended if the second is not working or you really need ad-hoc reindexing, because modifying files like this is inadvisable even if the changes are merely syntax changes to keep pace.

2. The second and perhaps cleaner is to apply a cron job from your control panel (assuming ofcourse it is allowed) to perform automatic scheduled indexing of your Magento Environment, as discussed in detail earlier. Below is the specific CLI command.

3. The 3rd and easiest if your host allows is to change PHP version (so that it changes for terminal also – not just for the specific directory) from 7.2 to 7.0 . However this may not be possible unless you are on VPS or own server.


* * * * * 'path to php binary' 'magento install dir'/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/log/magento.cron.log

Note: The trick here is to opt for Php 7.0 to run this cron job as Php 7.2 or whatever is the root PHP version may not be compatible with the files we spoke about earlier. This can be done as shown below:

/opt/php70/bin/php 'path to the magento install directory... and remaining code as above'

where /opt/php70/bin/php is the path to the php 7.0 binary instead of 7.2.

Pros with Cron based Re-indexing in Magento 2

1. Since it is automated, it does not involve getting tied up with obscure terminal software and typing in CLI. More User Friendly as well.
2. Easier and more practical for in-production stores where regular Inventory, Price changes as well as new product additions keeps happening.

Cons of Cron based Re-indexing in Magento 2

1. Cron should not be very frequent if your website does not undergo frequent product uploads. Can set it with a few minute interval. It will check every few minutes if any re-indexing is required, it does the needful.
2. Sometimes you need to do an ad-hoc re-indexing during development after a specific change.

Are you looking for Magento 2 Installation and Magento 2 Website / Portal Development, Customization by any chance ?. We are based out of New Delhi, India servicing globally. Write in to us with your Magento 2 / Ecommerce web design requirements and we will be happy to provide a solution.
Inquire Here

Previous Article

What Features to add in your On ...

Next Article

Hybrid App Development through Xamarin for Miami ...

Umesh Sethi

Our company helps convert ideas into mobile apps. We work with international clients and clients in Delhi NCR. As the Project Manager i like sharing tips, tricks and suggestions with clients and partners

Related articles More from author

  • how to find the best custom software development company in India
    Small Businesses & Startups

    How to Choose the best custom software development companies in India ?

    August 28, 2020
    By Abhay Anand
  • Web Design for Business Owners: What type of website design does your business need ?
    Small Businesses & StartupsWeb

    Tutorial 2: Which type of website does your business need ?

    March 11, 2020
    By Saurabh Kumar
  • find a florida xamarin mobile app development company near you
    Mobile App DevelopmentSmall Businesses & Startups

    Hybrid App Development through Xamarin for Miami & Florida

    March 19, 2019
    By Abhay Anand
  • How to Create a Requirements document for Mobile App - step wise article
    Mobile App DevelopmentSmall Businesses & Startups

    How to create a requirements document for your Mobile App ? (Steps and Tips)

    November 25, 2018
    By Umesh Sethi
  • Top 6 logistics mobile apps for India for 2018
    New App ReviewsNewsSmall Businesses & Startups

    6 of the Best Trucking , Moving and Logistics Apps of India for 2018

    December 4, 2017
    By Umesh Sethi
  • 5 tips to launch your ecommerce store successfully
    Web

    5 practical tips to make your Ecommerce Store a Success

    June 24, 2020
    By Umesh Sethi

Recommended Articles

  • Android Tutorials & TipsMobile App Development

    10 Best Practices for Mobile App Development in 2018 (updated for 2019)

  • Membership Website Development Company from India, using Wordpress
    Small Businesses & StartupsWeb

    How to get a great membership website developed using wordpress !

  • Choosing a great domain name for your website
    Small Businesses & StartupsWeb

    How to Choose the Best Domain name for your website (20 tips , steps & tools)

  • Web

    Websites for Business Owners – Tutorial 1 – Market Research for your website

Web Design & App Tutorials

  • March 6, 2026

    AI & ML Use Cases for Ecommerce in 2026 – Indian Context

  • November 7, 2020

    10 Tips To Grow Your Online Business

  • October 3, 2020

    10 Reasons to use Woocommerce for your E-commerce Development

  • September 4, 2020

    21 steps to Create a successful e-commerce store ! (Ultimate Guide)

  • August 28, 2020

    How to Choose the best custom software development companies in India ?

  • July 31, 2020

    7 Best Lead Generation Plugins for WordPress in 2020 & beyond

  • July 24, 2020

    7 Tasks to Complete before Starting Your Website Development Project

  • June 24, 2020

    5 practical tips to make your Ecommerce Store a Success

  • May 11, 2020

    Tutorial 4: How to choose the best theme for your business website ?

  • April 17, 2020

    Online Marketing Tips and Productivity Tools for Small Businesses during Coronavirus

  • March 31, 2020

    Tutorial 3 – How to Create a Project Plan / To Do List for your Website Design Project

  • March 11, 2020

    Tutorial 2: Which type of website does your business need ?

Check our Earlier Posts

  • March 2026
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • September 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • Recent

  • Popular

  • Comments

  • AI ML Use Cases in Ecommerce

    AI & ML Use Cases for Ecommerce in 2026 – Indian Context

    By Editorial Staff
    March 6, 2026
  • online marketing dashboard opened

    10 Tips To Grow Your Online Business

    By Editorial Staff
    November 7, 2020
  • 10 Reasons to use Woocommerce for your E-commerce Development

    By Saurabh Kumar
    October 3, 2020
  • 21 steps to creating your ecommerce store

    21 steps to Create a successful e-commerce store ! (Ultimate Guide)

    By Umesh Sethi
    September 4, 2020
  • how to find the best custom software development company in India

    How to Choose the best custom software development companies in India ?

    By Abhay Anand
    August 28, 2020
  • Top 10 Bitcoin Apps for 2018

    The Best Bitcoin mobile apps to watch out for in 2018

    By Saurabh Kumar
    December 23, 2017
  • iPhone 8 specifications, iPhone 8 Actual features

    Does the iPhone 10 or iPhone X meet users expectations? Features, Specifications, Details

    By Saurabh Kumar
    September 12, 2017
  • Google Tez App launch in India

    Google Tez App launched – Tez App Review and How to use it.

    By Umesh Sethi
    September 18, 2017
  • mobile app development, mobiile app programming, Java vs. Kotlin

    Kotlin vs. Java for Android App Development – And the winner is….

    By Umesh Sethi
    September 9, 2017
  • Creating a Requirements Document for Mobile App Development

    What should a Requirements Document (or a RFP) for your Mobile App Contain ?

    By Umesh Sethi
    October 17, 2017
  • Shailesh Manjrekar
    on
    September 12, 2020

    21 steps to Create a successful e-commerce store ! (Ultimate Guide)

    Thank you so much, ...
  • Maulik Shah
    on
    September 12, 2020

    How to Choose the best custom software development companies in India ?

    Such an informative post.Thanks ...
  • mayank
    on
    September 4, 2020

    How to Choose the best custom software development companies in India ?

    It's very wonderful information ...
  • Upendra
    on
    August 6, 2020

    7 Tasks to Complete before Starting Your Website Development Project

    Thanks for this blog ...
  • Bharat
    on
    July 7, 2020

    5 practical tips to make your Ecommerce Store a Success

    A very nice content ...

Our Terms of Use | Partners

Visit blogadda.com to discover Indian blogs
Featured on Blog Directory
Creative Spark Solutions is a web & app development company based in Delhi, India. With this blog we continue to connect with developers, clients and anyone interested in mobile & tech news, happenings & articles.
2017, Creative Spark Solutions helping clients in Web, Mobile & Software