Fatal error: Uncaught Error: Class 'Cli' not found

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


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 ;]

Tags:

Php

Magento2