Laravel: PHP Artisan Migrate throws PDO Exception: Could not find driver (Postgres)

23,279

Solution 1

you should install PHP pdo

sudo apt upgrade 
sudo apt install php-pgsql

Solution 2

i'v been through the same situation, try the following in order,

1) install the postgre extensions for php, those are:
   php-(YOUR_VERSION)-pgsql, and php-pgsql.
2) enable pgsql extensions in your php.ini file, basically, 
   uncomment the the extensions. 
3) restart the apache server(or nginx).
4) check that extensions are enable using phpinfo() or any else tool.
5) set a password for (in instance) the postgres user in postgreSQL 
   server, this is a very important step.

login to the psql shell:

sudo su - postgres
\password postgres

enter a password and confirm it.

now, set your .env file and try again.

Share:
23,279
user968270
Author by

user968270

Updated on September 25, 2020

Comments

  • user968270
    user968270 over 3 years

    OS: Ubuntu 16.10

    Server: Nginx

    DB: PostgreSQL 9.5.4

    Laravel 5.4

    Trying to perform my database migrations, but php artisan migrate throws the following error:

    [Illuminate\Database\QueryException] could not find driver: (SQL select * from information_schema.tables where tables_schema = username and table_name = migrations)

    Followed by a second message stating

    [PDOException]

    could not find driver

    I have done the following:

    1. Verified that I have php-pgsql's latest version installed
    2. Uncommented the line pertaining to php_pdo_pgsql.dll in /etc/php/7.0/fpm/php.ini
    3. Restarted both posgtresql and nginx multiple times

    Currently, when I run php -i, the output I get for the PDO section is

    PDO support => enabled

    PDO drivers => pgsql

    The pdo_pgsql section yields

    PostgreSQL(libpq) Version =>9.5.4

    Module version =>7.0.15-0ubuntu0.16.10.4

    And the pgsql section returns

    PostgreSQL(libpq) Version = 9.5.4

    PostgreSQL(libpq) => PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 6.1.1-11ubuntu12) 6.1.1 20160805, 64-bit Multibyte character support => enabled

    SSL support => enabled

    Active Persistent Links => 0

    Active Links => 0

    But in spite of this, still getting the same error. I thought there was some chance it might be a permissions problem, but running the command as either root or www-data has the same result.

  • lewis4u
    lewis4u about 7 years
    If you want I can help you over teamviewer, you probably made some small mistake, but it's always hard to tell what is wrong if you can't see