Skip to content
Latchkey

Laravel "could not find driver" (PDO extension) in CI

PDO has no driver registered for the database you configured. The matching PHP extension (pdo_mysql, pdo_pgsql, or pdo_sqlite) is not compiled or enabled in the CI PHP build. Add it to the setup-php extensions list.

What this error means

The first query fails with "SQLSTATE[HY000] ... could not find driver" or "PDOException: could not find driver", regardless of credentials, because the PDO driver extension is missing.

php artisan
  Illuminate\Database\QueryException

  could not find driver (Connection: mysql, SQL: select 1)

Common causes

The PDO driver extension is not enabled

The CI PHP build lacks pdo_mysql (or pdo_pgsql/pdo_sqlite) for the DB you use, so PDO has no driver to open the connection.

DB_CONNECTION does not match an installed driver

You configured mysql but only pdo_sqlite is present, so PDO cannot construct a mysql connection.

How to fix it

Add the driver via setup-php extensions

  1. List the PDO driver your DB_CONNECTION needs in setup-php.
  2. Include the base pdo extension where required.
  3. Re-run so PHP loads the driver before Laravel connects.
.github/workflows/ci.yml
- uses: shivammathur/setup-php@v2
  with:
    php-version: '8.3'
    extensions: mbstring, pdo, pdo_mysql, pdo_sqlite

Match the extension to DB_CONNECTION

For Postgres use pdo_pgsql, for sqlite use pdo_sqlite. Enable the one matching DB_CONNECTION.

.github/workflows/ci.yml
extensions: pdo_pgsql   # DB_CONNECTION: pgsql

How to prevent it

  • Declare every needed PDO driver in setup-php extensions.
  • Keep the enabled driver aligned with DB_CONNECTION.
  • Verify with php -m | grep pdo early in the job.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →