2

E:\xampp\htdocs\magento-2>php -dmemory_limit=5G bin/magento setup:di:compile The directory "E:/xampp/htdocs/magento-2/var/generation/Magento/Framework" canno t be deleted Warning!rmdir(E:/xampp/htdocs/magento-2/var/generation/Magento/Fram ework): Directory not empty#0 E:\xampp\htdocs\magento-2\vendor\magento\framework \Filesystem\Driver\File.php(403): Magento\Framework\Filesystem\Driver\File->dele teDirectory('E:/xampp/htdocs...')

  1. E:\xampp\htdocs\magento-2\vendor\magento\framework\Filesystem\Driver\File.php (403): Magento\Framework\Filesystem\Driver\File->deleteDirectory('E:/xampp/htdoc s...')
  2. E:\xampp\htdocs\magento-2\setup\src\Magento\Setup\Console\CompilerPreparation .php(68): Magento\Framework\Filesystem\Driver\File->deleteDirectory('E:/xampp/ht docs...')
  3. E:\xampp\htdocs\magento-2\vendor\magento\framework\Console\Cli.php(74): Magen to\Setup\Console\CompilerPreparation->handleCompilerEnvironment()
  4. E:\xampp\htdocs\magento-2\bin\magento(22): Magento\Framework\Console\Cli->__c onstruct('Magento CLI')
  5. {main} PHP Fatal error: Class 'Cli' not found in E:\xampp\htdocs\magento-2\bin\magento on line 31

Fatal error: Class 'Cli' not found in E:\xampp\htdocs\magento-2\bin\magento on l ine 31

7

Removed your var/generation directory and var/cache directory.

You need to remove it manually, if it is ubuntu then locate in your magento 2 root directory and run rm -rf var/generation and rm -rf var/cache command.

Then try to run below commands in sequence.

  • php bin/magento setup:di:compile
  • php bin/magento setup:upgrade
  • php bin/magento cache:clean
  • php bin/magento cache:flush
| improve this answer | |
  • mine is a windows system – learner Jun 23 '17 at 9:59
  • @Priya then remove it manually. – Manthan Dave Jun 23 '17 at 11:05
  • @ManthanDave In windows wamp i removed generation, still showing error like : The directory "C:/wamp64/www/magento2/generated/code/Magento/Framework/App" ca ot be deleted Warning!rmdir(C:/wamp64/www/magento2/generated/code/Magento/Fram ork/App): Directory not empty How to solve the error? – zus Feb 21 at 11:57
  • @ManthanDave Screenshot : snipboard.io/FYa9EU.jpg – zus Feb 21 at 12:00
  • I think, one should run the setup:upgrade command first and then the setup:di:compile – VishalParkash Sep 29 at 10:41
3

If production mode, put site into maintenance mode first.

bin/magento maintenance:enable
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy
bin/magento cache:flush
// If running as root instead of www-data for example you may need to chown/chmod.
// chown -R www-data:www-data .

bin/magento maintenance:disable

Maybe it is because stuff is being generated as bots/users try to access the site?

Note: If you use other locales you would want to setup:static-content:deploy those as well.

I think you can specify multiple after the statup:static-content:deploy en_US en_GB en_NZ etc...

See more here: https://devdocs.magento.com/guides/v2.4/install-gde/install/cli/install-cli-subcommands-maint.html

You might need to take ownership of the folder first or shell in as the Magento filesystem owner.

| improve this answer | |
  • 1
    This is definitely the right answer; if you don't enable maintenance mode first you will get spammed with The directory "/var/www/html/generated/code/Magento" cannot be deleted Warning!rmdir(/var/www/html/generated/code/Magento): Directory not empty for many directories. Enabling maintenance mode first and waiting a bit for in-flight requests to finish really is the solution here – Justin Oct 24 at 14:28

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.