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.