cake phpエラー[MissingConnectionException] Database connection “Mysql” is missing, or could not be created.が発生した場合

cake phpエラー[MissingConnectionException] Database connection “Mysql” is missing, or could not be created.が発生した場合

cake phpに、エラー[MissingConnectionException] Database connection “Mysql” is missing, or could not be created.が発生した場合の対処法を記述してます。

環境

  • OS  AlmaLinux 8.4
  • php 7.4

エラー全文

以下のエラーが発生して「An Internal Error Has Occurred.」が発生

Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created.
Exception Attributes: array (
  'class' => 'Mysql',
  'message' => 'Selected driver is not enabled',
  'enabled' => false,
)
Request URL: /
Stack Trace:
#0 /var/www/html/lib/Cake/Model/ConnectionManager.php(105): DboSource->__construct()
#1 /var/www/html/lib/Cake/Model/Model.php(3659): ConnectionManager::getDataSource()
#2 /var/www/html/lib/Cake/Model/Model.php(1162): Model->setDataSource()
#3 /var/www/html/lib/Cake/Model/Model.php(3686): Model->setSource()
#4 /var/www/html/lib/Cake/Model/Model.php(3488): Model->getDataSource()
#5 /var/www/html/app/Model/Setting.php(60): Model->query()
#6 /var/www/html/app/Controller/AppController.php(74): Setting->getSettings()
#7 /var/www/html/lib/Cake/Event/CakeEventManager.php(244): AppController->beforeFilter()
#8 /var/www/html/lib/Cake/Controller/Controller.php(682): CakeEventManager->dispatch()
#9 /var/www/html/lib/Cake/Routing/Dispatcher.php(189): Controller->startupProcess()
#10 /var/www/html/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke()
#11 /var/www/html/app/webroot/index.php(139): Dispatcher->dispatch()
#12 {main}

対処法

自分の場合は「php-mysql」をインストールして改善
※phpバージョンが、7.4を指定しているので「php74-php-mysql」をインストールしてます。

sudo dnf install php74-php-mysql