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
Why 'could not find driver' happens in Laravel and how to fix it — what actually worked for me on Amazon Linux, plus researched notes for Ubuntu/macOS/Docker.
Error Message
Illuminate\Database\QueryException
could not find driver (Connection: mysql, SQL: ...)This shows up when Laravel tries to connect to the database — typically on php artisan migrate or the first request that touches the DB.
Cause
This error means PHP is missing (or hasn't enabled) the PDO driver for your database.
Laravel connects to the database through PDO internally, so besides PHP itself, you need a separate extension for whichever database you're connecting to.
| Database | Required extension |
|---|---|
| MySQL / MariaDB | pdo_mysql |
| PostgreSQL | pdo_pgsql |
| SQLite | pdo_sqlite |
| SQL Server | pdo_sqlsrv |
In most cases, config/database.php is set up for a mysql connection, but pdo_mysql simply isn't installed.
How to Check
First, check whether the extension is actually loaded:
php -m | grep pdoIf you don't see an entry for your database (e.g. pdo_mysql), that's the cause.
CLI and your web server (php-fpm, etc.) can sometimes run different PHP binaries, so if you want to check what the web server sees, output phpinfo() for a more reliable check.
Solution (What Actually Fixed It for Me)
I hit this error on Amazon Linux 2023 (dnf), and installing php-mysqlnd fixed it.
sudo dnf install -y php-mysqlndReference: Other Environments
The underlying cause is the same regardless of environment (a missing PDO driver), so installing the matching package should fix it elsewhere too.
I haven't personally tested these, but here's what I found while researching (swap mysql for pgsql etc. if you're connecting to a different database).
Ubuntu / Debian-based
apt install -y php-mysql reportedly does the same job.
sudo apt install -y php-mysqlYou may need a version-specific package (e.g. php8.3-mysql) — apparently it's worth matching this to the PHP version from php -v.
macOS (Homebrew)
Homebrew's php package reportedly bundles pdo_mysql already.
If it's still missing from php -m, reinstalling reportedly fixes it in most cases.
brew reinstall phpDocker
You apparently need to install the extension explicitly in your Dockerfile.
RUN docker-php-ext-install pdo_mysqldocker-php-ext-install is only available on the official PHP images (php:*-fpm, etc.), from what I can tell.
If you're on a different base image, the package install command for that distribution should work instead.
After Installing
Installing the package alone doesn't always take effect immediately.
- Restart php-fpm / Apache / Nginx
sudo systemctl restart php-fpm - Check
php.inito make sure the extension isn't commented out (;extension=pdo_mysql) - For Docker, rebuild the container — a cached image layer can leave the old state in place
Run php -m | grep pdo again afterward to confirm the driver now shows up.
Background
While deploying a Laravel project on AWS EC2 (Amazon Linux 2023), I ran the following command and hit the error at the top of this post.
php artisan migrateBeforehand, I had only run this to install PHP itself.
sudo dnf install -y php8.3Unlike yum, dnf prints logs that make it look like it's automatically pulling in every related driver with a single command, so I assumed that was enough.
In reality, the PDO driver for MySQL (php-mysqlnd) needed to be installed as a separate package.
sudo dnf install -y php-mysqlndRunning this and restarting php-fpm resolved it.
What to Include When Asking an AI Chat Tool
If you're asking an AI chat tool (ChatGPT, Claude chat, etc. — not an agent that can run commands itself), you'll need to describe your situation yourself.
Pasting the following gets you a much more accurate answer:
- The full error message (including the stack trace, don't trim it)
- Output of
php -v(your PHP version) - Output of
php -m(loaded extensions, especially anything starting withpdo_) - Your environment (OS and version — Amazon Linux 2023 / Ubuntu 22.04 / macOS + Homebrew / Docker, etc.)
- The relevant connection block in
config/database.php(which connection you're actually using) - The
.envvalue forDB_CONNECTION(redact any secrets) - If you're using Docker, the PHP install section of your Dockerfile
- Which fix from this article you already tried, and what happened (including whether the error message changed)
The php -m output and your environment are almost always essential for narrowing down the cause — send those two first if nothing else.
Summary
could not find driver doesn't mean PHP itself is broken — it almost always means the PDO extension for your target database isn't installed.
Check what's loaded with php -m, install the right package for your environment, and restart the service.

Written by
Matsun
A software engineer with 6 years of experience, mainly in server-side development. I independently build and operate a production startup service, working full-stack across Laravel, JavaScript, and AWS. Since 2019, I've been sharing the real-world problems and solutions I encounter.




