How to Resolve 'could not find driver' Error in Laravel
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
This article explains how to resolve the 'could not find driver' error when running php artisan migrate
in Laravel.
Error Message
Illuminate\Database\QueryException
could not find driver (Connection: mysql, SQL ....)
Environment
AWS EC2 (Amazon Linux 2023)
PHP 8.3
Laravel 11
Solution
The issue was resolved by installing the missing php-mysqlnd
package.
sudo dnf install -y php-mysqlnd
Background
While deploying a Laravel project on AWS EC2 (Amazon Linux 2023), I encountered the following error when running:
php artisan migrate
Previously, I had only run the following command for PHP:
sudo dnf install -y php8.3
Unlike yum
, dnf
automatically installs various necessary drivers with just one command, and I saw logs indicating that it was doing so. Based on that, I thought this single command would suffice.
However, the error occurred only during migration, so I ran one additional command to resolve the issue.
The solution may vary depending on your environment and approach, but I hope this helps someone facing the same issue.