27

After firing this command in CLI php bin/magento setup:upgrade

I am getting below error -:

Fatal error: Uncaught exception 'Magento\Framework\Exception\LocalizedException' with message 'Can't create directory 
/var/www/html/magento/magento2.0/var/generation/Magento/Framework/App/ResourceConnection/.' in 
/var/www/html/magento/magento2.0/vendor/magento/framework/Code/Generator.php:103
Stack trace:
#0 /var/www/html/magento/magento2.0/vendor/magento/framework/Code/Generator/Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Magento\\Framewo...')
#1 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Framewo...') #2 [internal function]: spl_autoload_call('Magento\\Framewo...')
#3 /var/www/html/magento/magento2.0/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Magento\\Framewo...')
#4 /var/www/html/magento/magento2.0/vendor/magento/framework/ObjectManager/Definition/Runtime.php(44): Magento\Framework\Code\Reader\ClassReader->getConstructor('Magento\\Framewo...')
#5 /var/www/html/magento/magento2.0/vendor/magento/framework/ObjectMana in /var/www/html/magento/magento2.0/vendor/magento/framework/Code/Generator.php on line 103`
34

I have solved this problem by just simply doing this steps. follow steps :

  1. Delete the "di" folder located in var directory (for 2.0 and 2.1)
  2. Run this command and go to your project root folder command:

    cd /yourmagentoroot/
    

    If your Magento mode is developer then you don't need to run below commands just remove var/generation directory(2.0 & 2.1) or generated folder(2.2 onwards)

  3. Then run this command

    php bin/magento setup:di:compile
    
  4. Then run this command (required in production mode only)

    php bin/magento setup:static-content:deploy
    
  5. Finally, give file/directory permissions.(If needed)

| improve this answer | |
  • How can i solve SUDO : snag.gy/hC5JDL.jpg – zus Oct 27 '17 at 11:59
  • 1
    @zus in windows try without sudo – Murtuza Zabuawala Oct 27 '17 at 12:13
  • How to give file/directory permissions in wamp windows? @Murtuza Zabuawala – Gem Feb 20 at 12:32
  • @Gem I think in windows its not needed – Murtuza Zabuawala Feb 21 at 4:50
  • @gem in linux if your user and php user is different then this issue might arise – Murtuza Zabuawala Feb 21 at 4:51
31

Giving full control (read/write/execute) to var and pub directory solved this issue for me.

sudo chmod -R 777 var pub

Or, you may also try running the command using sudo.

sudo php bin/magento setup:upgrade

Also, try clearing cache.

sudo rm -rf var/cache/* var/generation/*
| improve this answer | |
  • In some cases if you have sudo access to magento filesystem owner or webserver user(www-data/nginx). You can execute command like this: sudo -u www-data bin/magento list-- – Diwaker Mar 3 '17 at 9:00
12

Setup ownership again

CentOS: chown -R :apache .
Ubuntu: chown -R :www-data .

Refer this Link

| improve this answer | |
  • now i am getting this error – Murtuza Zabuawala Nov 27 '15 at 12:38
  • 1
    Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/magento/magento2.0/vendor/magento/framework/Code/Generator/EntityAbstract.php on line 152 Notice: Uninitialized string offset: 0 in /var/www/html/magento/magento2.0/vendor/magento/framework/Autoload/ClassLoaderWrapper.php on line 81 Notice: Uninitialized string offset: 0 in /var/www/html/magento/magento2.0/vendor/composer/ClassLoader.php on line 317 Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/magento/magento2.0/vendor/magento/framework/Code/Generator/EntityAbstract.php on line – Murtuza Zabuawala Nov 27 '15 at 12:39
  • 1
    @murtuza please clear your var/generation folder and cache dirs within var and try again. – Maddy Dec 11 '15 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.