PHP error guide
PDO "could not find driver": Install and Enable the Correct PHP Driver
Error summary
PDO has no driver for the DSN prefix (often `mysql:`). Install/enable the matching PDO driver for the same PHP SAPI that runs the site, then restart PHP-FPM/Apache.
What it means
PDO has no driver for the DSN prefix (often mysql:). Install/enable the matching PDO driver for the same PHP SAPI that runs the site, then restart PHP-FPM/Apache.
What the error means
The PDO extension is present enough to construct PDO, but the driver module for that database (pdo_mysql, pdo_pgsql, …) is not loaded.
Why PHP produces it
PDO is modular. mysql:host=... requires pdo_mysql (and usually the underlying client libraries).
PHP version notes
Exact package names differ by distro and PHP minor version.
Most common causes
pdo_mysqlnot installed for the active PHP version- CLI has the driver but FPM does not
- Wrong DSN prefix
- Container image missing DB extensions
Minimal examples
BAD — reproduces the problem
$pdo = new PDO('mysql:host=127.0.0.1;dbname=app', $user, $pass);
FIXED — safer pattern
if (!extension_loaded('pdo_mysql')) {\n throw new RuntimeException('Enable pdo_mysql');\n}\n$pdo = new PDO('mysql:host=127.0.0.1;dbname=app;charset=utf8mb4', $user, $pass, [\n PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,\n]);
Step-by-step diagnosis
- Print
PDO::getAvailableDrivers()in the failing SAPI. - Compare
php -mfor CLI vs FPM phpinfo modules. - Confirm DSN starts with an installed driver name.
Fixes
Fix #1: Install pdo_mysql for the site PHP version
Package names vary; install for the same version Virtualmin/FPM uses.
php -m | grep -i pdo\n# install php-mysql / php8.3-mysql (distro-specific)\nsudo systemctl restart php-fpm
Fix #2: Verify drivers in code
Fail fast with a clear message during bootstrap.
if (!in_array('mysql', PDO::getAvailableDrivers(), true)) {\n throw new RuntimeException('pdo_mysql is not enabled');\n}
Common mistakes when fixing it
- Installing
mysqlibut notpdo_mysqlwhen the app uses PDO
How to prevent it
- Composer
ext-pdo_mysqlrequirement - Smoke test DB bootstrap in deploy
Web server / environment notes
Docker/Alpine images often omit DB drivers by default
Tags: fpm,cli,docker,linux
Categories
Related PHP errors
Relevant ZendStudio.net tools
- Composer Platform Checker Paste composer.json to list PHP constraints and ext-* platform requirements without running Compose…
- PHP Configuration Inspector Paste php --ini output or selected directive lines to identify loaded ini files and key limits.
- PHP Error Matcher Paste a full PHP error, warning, SQLSTATE, or cURL message to find the best ZendStudio.net troubles…