Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

grunburg's avatar

Trouble connecting to PostgreSQL database.

When command php artisan migrate is ran, I get this error:

Illuminate\Database\QueryException 

could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
  667|  // If an exception occurs when attempting to run a query, we'll format the error
  668|  // message to include the bindings with SQL, which will make this exception a
  669|  // lot more helpful to the developer instead of just the database's errors.
  670|  catch (Exception $e) {
> 671|      throw new QueryException(
  672|          $query, $this->prepareBindings($bindings), $e
  673|      );
  674|  }
  675| 

 +34 vendor frames 
  35  artisan:37
  Illuminate\Foundation\Console\Kernel::handle()

This is my .env file:

DB_CONNECTION=pgsql
DB_HOST=host.docker.internal
DB_PORT=5432
DB_DATABASE=name
DB_USERNAME=user
DB_PASSWORD=secret

And checking phpinfo() within Laravel App, I can confirm that pgsql and pdo_pgsql extensions are installed.

Also by doing php -m inside docker CLI, both extensions are there.

Been on this error for some quite time and still can't figure out what's wrong. I hope someone can help me with this mess... :(

Edit: forgot to add my Dockerfile

FROM php:7.4-fpm

RUN apt-get update && apt-get install -y libpq-dev

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql

RUN docker-php-ext-install pdo pdo_pgsql pgsql bcmath
0 likes
2 replies
just_v's avatar

Hi, make sure you have installed php and php-pgsql extension on your linux / mac / windows pc.

And don't forget to add this thing 127.0.0.1 host.docker.internal to your hosts file.

Reboot.

Then cd to your project and try again php artisan migrate.

Please or to participate in this conversation.