Solved: PHP Fatal Error: Class ‘CLI’ was not found in ‘bin\Magento’ on line 31

Magento2 is full of surprises and I am loving and hating it at the same time. I fix one issue and another issue comes up sooner or later.

Mostly, I have been using Ubuntu for Magento 2 development but I decided to try it on Windows to test the platform performance. Installation was nice and easy and I was able to install demo data without any issue.

After setting up the initial version, I decided to create my own extension which involved a few frontend templating.¬†Everything was normal until I ran ‘php bin\magento setup:di:compile’. Screenshot below.

Magento CLI fatal errorI was served with a fatal error and after scratching my head a few times – and of course hitting on the wall a few times, I decided to remove var/generation directory. It all went fine this time. Alright, so to cut the long store short, do the following:


  1. Don’t panic
  2. Take a deep breath
  3. Remove {magento_directory}/var/generation/
  4. Run ‘php bin/magento setup:di:compile’ again

Did it fix your issue? Drop a comment below to let me know.

Solved: Class Magento\Catalog\Api\Data\ProductSearchResultsInterfaceFactory does not exist

Magento 2 generates Factory classes inside var/generation directory. So, if there is folder permission issue or folder owner issue with that directory then the factory class cannot be generated and you get such error.

When you clear var/generation directory and set appropriate permission to it then this error should be solved.

T0 update the directory permissions, do the following:


  • Open your linux terminal, on Ubuntu you can access it by pressing Ctrl + Alt + T
  • On the terminal ¬†window, Go to your Apache/Nginx directory e.g. var/www/html/{Magento Directory}
  • Type ‘sudo chmod 775 -R {Magento Directory}/’ and hit enter.
  • Alternatively, you can apply 777 permission to your {Magento Directory} as well but it is not recommended.