6

Someone changed my php version for my magento 2 website to 5.6 and I changed it back to 7.0 and now I'm getting this error when I try to run the major magento commands such as compile and system:upgrade

The file "/var/www/vhosts/ooples.com/httpdocs/var/generation/Composer/Console/ApplicationFactory.php" cannot be deleted Warning!unlink(/var/www/vhosts/ooples.com/httpdocs/var/generation/Composer/Console/ApplicationFactory.php): Permission denied#0 /var/www/vhosts/ooples.com/httpdocs/lib/internal/Magento/Framework/Filesystem/Driver/File.php(405): Magento\Framework\Filesystem\Driver\File->deleteFile('/var/www/vhosts...') 1 /var/www/vhosts/ooples.com/httpdocs/lib/internal/Magento/Framework/Filesystem/Driver/File.php(403): Magento\Framework\Filesystem\Driver\File->deleteDirectory('/var/www/vhosts...') 2 /var/www/vhosts/ooples.com/httpdocs/lib/internal/Magento/Framework/Filesystem/Driver/File.php(403): Magento\Framework\Filesystem\Driver\File->deleteDirectory('/var/www/vhosts...') 3 /var/www/vhosts/ooples.com/httpdocs/setup/src/Magento/Setup/Console/CompilerPreparation.php(68): Magento\Framework\Filesystem\Driver\File->deleteDirectory('/var/www/vhosts...') 4 /var/www/vhosts/ooples.com/httpdocs/lib/internal/Magento/Framework/Console/Cli.php(74): Magento\Setup\Console\CompilerPreparation->handleCompilerEnvironment() 5 /var/www/vhosts/ooples.com/httpdocs/bin/magento(22): Magento\Framework\Console\Cli->__construct('Magento CLI') 6 {main}

PHP Fatal error: Uncaught Error: Class 'Cli' not found in /var/www/vhosts/ooples.com/httpdocs/bin/magento:31 Stack trace: 0 {main} thrown in /var/www/vhosts/ooples.com/httpdocs/bin/magento on line 31

Fatal error: Uncaught Error: Class 'Cli' not found in /var/www/vhosts/ooples.com/httpdocs/bin/magento:31 Stack trace: 0 {main} thrown in /var/www/vhosts/ooples.com/httpdocs/bin/magento on line 31

What can I do to fix this error?

UPDATE: Here are the results when I run rm -rf var

rm: cannot remove ‘var/di/setup.ser’: Permission denied
rm: cannot remove ‘var/di/webapi_rest.ser’: Permission denied
rm: cannot remove ‘var/di/frontend.ser’: Permission denied
rm: cannot remove ‘var/di/global.ser’: Permission denied
rm: cannot remove ‘var/di/adminhtml.ser’: Permission denied
rm: cannot remove ‘var/di/crontab.ser’: Permission denied
rm: cannot remove ‘var/di/webapi_soap.ser’: Permission denied
asked Nov 29, 2016 at 4:34
6
  • have you tried clearing var/generation and tring again ? also check file permissions and owner of that folder Commented Nov 29, 2016 at 4:55
  • remove var folder and try to run compile command. Commented Nov 29, 2016 at 5:00
  • @VishwasBhatnagar I tried clearing the var/generation but I get a bunch of access denied errors and I have given myself full permission for that folder Commented Nov 29, 2016 at 5:00
  • @Rakesh I have always been able to run this as my normal username in ssh but it suddenly doesn't work anymore. I confirmed that sudo works but I need to figure out the root issue as to why my normal account no longer works to delete that folder Commented Nov 29, 2016 at 5:52
  • share the "bunch of access denied errors " sample Commented Nov 29, 2016 at 5:58

6 Answers 6

3

This error has nothing to do with Plesk it's from the Magento script itself. Whoever wrote it clearly has no idea of PHP OOP. Sorry but it's true.

There's nowhere to be found an "use" keyword in the script but you can clearly see that he's trying to use

 Cli

class without specifying the namespace. That's the whole error if you change it to

 Magento\Framework\Console\Cli

it will work.

Change the bin/magento shell file from:

#!/usr/bin/env php
<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
if (PHP_SAPI !== 'cli') {
 echo 'bin/magento must be run as a CLI application';
 exit(1);
}
try {
 require __DIR__ . '/../app/bootstrap.php';
} catch (\Exception $e) {
 echo 'Autoload error: ' . $e->getMessage();
 exit(1);
}
try {
 $handler = new \Magento\Framework\App\ErrorHandler();
 set_error_handler([$handler, 'handler']);
 $application = new Magento\Framework\Console\Cli('Magento CLI');
 $application->run();
} catch (\Exception $e) {
 while ($e) {
 echo $e->getMessage();
 echo $e->getTraceAsString();
 echo "\n\n";
 $e = $e->getPrevious();
 }
 exit(Cli::RETURN_FAILURE);
}

to

#!/usr/bin/env php
<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
if (PHP_SAPI !== 'cli') {
 echo 'bin/magento must be run as a CLI application';
 exit(1);
}
try {
 require __DIR__ . '/../app/bootstrap.php';
} catch (\Exception $e) {
 echo 'Autoload error: ' . $e->getMessage();
 exit(1);
}
try {
 $handler = new \Magento\Framework\App\ErrorHandler();
 set_error_handler([$handler, 'handler']);
 $application = new Magento\Framework\Console\Cli('Magento CLI');
 $application->run();
} catch (\Exception $e) {
 while ($e) {
 echo $e->getMessage();
 echo $e->getTraceAsString();
 echo "\n\n";
 $e = $e->getPrevious();
 }
 exit(\Magento\Framework\Console\Cli::RETURN_FAILURE);
}

Take a look at the exit at the end...

Sorry if I offended somebody ;]

answered Jul 1, 2019 at 7:24
1
  • Namespaces != OOP per se. This apparent bug was fixed in Magento 2.2. It is indeed a shameful one, like Magento 2 overall :) Commented Apr 19, 2020 at 18:44
3

Ensure that you are using the correct php version. You must use the version that you used to install composer packages.

answered Jun 27, 2017 at 14:35
0

Make sure you have correct permission of edit and delete to var folder of Magento 2

answered Aug 30, 2017 at 12:05
0
0

I think , you are using plesk webhosting

So,Go for this path first.

cd /opt/plesk/php

ls

check PHP version is available or not.

IF exist..run below command

/opt/plesk/php/7.0/bin/php -dmemory_limit=1G bin/magento

Then run Magento Cli command as per your requirement.

answered Jun 15, 2018 at 10:36
0

I had this error as well.

Here is the steps I followed to correct the issue:

  1. Delete var/cache and var/generation folders.
  2. Check that you are running a supported php version.
  3. Made sure the apache process can write and read to the var/ folder.

  4. If it's still failing and you haven't changed any server or permission setting, move you app/code folder to a temp location and run the command again. The same error will display if you have a serious module issue. (This was my issue)

answered Jan 11, 2019 at 7:37
-1

am running kali linux debian gnome core

Creating config file /etc/php/7.2/mods-available/xsl.ini with new version
Setting up php-xml (1:7.2+62) ...
Processing triggers for libapache2-mod-php7.2 (7.2.9-1) ...
$ sudo php bin/magento setup:di:compile
Deprecated Functionality: The each() function is deprecated. This message will be suppressed on further calls in /opt/lampp/htdocs/magento2/vendor/magento/zendframework1/library/Zend/Cache/Backend.php on line 79#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8192, 'The each() func...', '/opt/lampp/htdo...', 79, Array)
#1 /opt/lampp/htdocs/magento2/vendor/magento/zendframework1/library/Zend/Cache/Backend.php(79): each(Array)
#2 /opt/lampp/htdocs/magento2/vendor/magento/zendframework1/library/Zend/Cache/Core.php(183): Zend_Cache_Backend->setDirectives(Array)
#3 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/Cache/Core.php(138): Zend_Cache_Core->setBackend(Object(Cm_Cache_Backend_File))
#4 /opt/lampp/htdocs/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(111): Magento\Framework\Cache\Core->setBackend(Object(Cm_Cache_Backend_File))
#5 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Cache/Frontend/Factory.php(154): Zend_Cache::factory('Magento\\Framewo...', 'Cm_Cache_Backen...', Array, Array, true, true, true)
#6 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php(67): Magento\Framework\App\Cache\Frontend\Factory->create(Array)
#7 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php(146): Magento\Framework\App\Cache\Frontend\Pool->_initialize()
#8 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php(84): Magento\Framework\App\Cache\Frontend\Pool->get('default')
#9 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Cache/Type/Config.php(49): Magento\Framework\App\Cache\Type\FrontendPool->get('config')
#10 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/Cache/Frontend/Decorator/Bare.php(65): Magento\Framework\App\Cache\Type\Config->_getFrontend()
#11 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader.php(66): Magento\Framework\Cache\Frontend\Decorator\Bare->load('global::DiConfi...')
#12 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/ObjectManager/Environment/Developer.php(77): Magento\Framework\App\ObjectManager\ConfigLoader->load('global')
#13 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/ObjectManagerFactory.php(194): Magento\Framework\App\ObjectManager\Environment\Developer->configureObjectManager(Object(Magento\Framework\Interception\ObjectManager\Config\Developer), Array)
#14 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Bootstrap.php(385): Magento\Framework\App\ObjectManagerFactory->create(Array)
#15 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/App/Bootstrap.php(362): Magento\Framework\App\Bootstrap->initObjectManager()
#16 /opt/lampp/htdocs/magento2/lib/internal/Magento/Framework/Console/Cli.php(79): Magento\Framework\App\Bootstrap->getObjectManager()
#17 /opt/lampp/htdocs/magento2/bin/magento(22): Magento\Framework\Console\Cli->__construct('Magento CLI')
#18 {main}
PHP Fatal error: Uncaught Error: Class 'Cli' not found in /opt/lampp/htdocs/magento2/bin/magento:31
Stack trace:
#0 {main}
 thrown in /opt/lampp/htdocs/magento2/bin/magento on line 31
Priyank
7,7627 gold badges39 silver badges70 bronze badges
answered Oct 16, 2018 at 11:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.