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? Leave a comment below to let others 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.


Solved: How to reset Magento 2 admin passwords using command line?


You must have SSH access to your server in order to use this method. If you do not have SSH access, contact your web host to get one.

  1. Log in to your server with SSH. You can either use Putty or OS Terminal to connect.

    1. Run ssh your-username@hostname/IP
    2. Enter your password when prompted
  2. Navigate to your Magento installation, but replace the bracketed placeholders accordingly:

    cd /[home]/[demo]/[]/[html]/

  1. Retrieve the admin user’s information from the database using the below command, but make the following adjustments:

    1. Replace [db_user] with your database user.

    2. Replace [db_name] with your database name.

    3. Within username=”[admin]'”, replace [admin] with the username requiring the reset. You will be prompted to for the database password before continuing.

      echo “select email,firstname,lastname from admin_user where username='[admin]'” | mysql -u [db_user] [db_name] -p

  1. To reset the password of a user, execute the following, but replace the bracketed placeholders between the quotation marks with the current user’s information:

    php bin/magento  admin:user:create –admin-user=”admin” –admin-password=”newpassword” –admin-email=””  –admin-firstname=”Test” –admin-lastname=”Test”

  2. hit enter and the password will be updated.


Echo template names/file paths like Magento in WordPress

Just paste the following code in your child theme’s functions.php file and it will display the template paths in wordpress. It is important to note that the path will only be visible to the logged in users so I highly recommend to remove this function from your codebase before deploying the website to LIVE.

 // REMOVE - show template name
 add_action('wp_head', 'show_template');
 function show_template() {
 global $template;
 global $current_user;
 if ($current_user->user_level == 10 ) print_r($template);
 // REMOVE - end show template name

Continue reading “Echo template names/file paths like Magento in WordPress”

Solved: Magento2 configurable product is ‘Out of Stock’


Sometimes it happens that you have associated products (Product configurations) in a configurable product but it shows ‘Out of stock’ on front-end despite that you have reindexed your Magento 2 and flushed the system cache as well.

Do the following If you experience the same issues:

  1. Whilst creating tte product configurations, make sure all configurations have the quantity assigned to them.
  2. If you do not assign the quantity at this stage then Magento2 will assume that the product is not in stock and it will change the stock status for all configurations to ‘Out of Stock’
  3. If you did not specify quantity for the configurations then you’d have to do so and change the status of all of the configurations from ‘Out of stock’ to ‘In Stock’ MANUALLY by going to the individual product editor.
  4. Once you have updated the stock status of the configurations, clear cache and reindex (Click here to learn how to reindex Magento2) Magento.
  5. Go back to the frontend product page, refresh the website and everything will be back to normal.