Php artisan optimnize error

v5.3.54-C75 self-hosted Ubuntu 20.04.3 LTS

php artisan optimnize
PHP Fatal error: During inheritance of PDO: Uncaught ErrorException: Return type of Doctrine\DBAL\Driver\PDOConnection::exec($sql) should either be compatible with PDO::exec(string $statement): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/ninja5/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50
Stack trace:
#0 /var/www/html/ninja5/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(22): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /var/www/html/ninja5/vendor/composer/ClassLoader.php(480): include(’…’)
#2 /var/www/html/ninja5/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#4 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(66): class_exists()
#5 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(46): Illuminate\Database\Connectors\Connector->createPdoConnection()
#6 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection()
#7 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(184): Illuminate\Database\Connectors\MySqlConnector->connect()
#8 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors{closure}()
#9 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(997): call_user_func()
#10 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(1033): Illuminate\Database\Connection->getPdo()
#11 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(426): Illuminate\Database\Connection->getReadPdo()
#12 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(352): Illuminate\Database\Connection->getPdoForSelect()
#13 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(685): Illuminate\Database\Connection->Illuminate\Database{closure}()
#14 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(652): Illuminate\Database\Connection->runQueryCallback()
#15 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Connection.php(360): Illuminate\Database\Connection->run()
#16 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php(44): Illuminate\Database\Connection->select()
#17 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Database\Schema\MySqlBuilder->hasTable()
#18 /var/www/html/ninja5/app/Exceptions/Handler.php(78): Illuminate\Support\Facades\Facade::__callStatic()
#19 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(366): App\Exceptions\Handler->report()
#20 /var/www/html/ninja5/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException()
#21 /var/www/html/ninja5/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#22 {main} in /var/www/html/ninja5/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 22

In Connection.php line 692:

could not find driver (SQL: select * from information_schema.tables where table_schema = ninjadb and table_name = accounts and table_type = ‘BASE TABLE’)

In Connector.php line 70:

could not find driver

@johnw

It looks like your cli version of PHP is 8.1, you’ll want to downgrade to PHP 8.0

root@infra:/var/www/html/ninja5# php artisan optimnize

Command “optimnize” is not defined.

Did you mean one of these?
optimize
optimize:clear

root@infra:/var/www/html/ninja5# php -v
PHP 8.0.15 (cli) (built: Jan 29 2022 07:24:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.15, Copyright (c) Zend Technologies
with Zend OPcache v8.0.15, Copyright (c), by Zend Technologies

The correct command is optimize

Thank @hillel

I made PHP 7.4 default as when I downgraded to PHP 8.0 didn’t work as well.