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.

2 Replies to “Solved: PHP Fatal Error: Class ‘CLI’ was not found in ‘bin\Magento’ on line 31”

    1. Hi Neeraj,

      What version of Magento are you using? Can you confirm that you are running the latest stable version? Also, it’s worth deleting page_Cache, di, generation and cache from var/ directory. Once done, run setup upgrade again and that should fix the issue.

Leave a Reply

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