简体   繁体   中英

Laravel: Error [PDOException]: Could not Find Driver (PostgreSQL)

I have seen a lot of topics about this error, but I think my case is specific. Here's the thing:

I had initially PHP 5.5.9 installed on my Ubuntu Server. In order to install the latest Laravel Framework I had to upgrade my PHP to 5.6. I used this guide to update. I also have PostgreSQL 9.3. Now, phpinfo tells me that I still have PHP 5.5.9 installed. However, php -v tells me that I have PHP 5.6. I have successfully installed Laravel and I'm able to connect to my database on my webpage (I can show fields from my table). But when I try to execute php artisan migrate in console I get the following error:

[PDOException]
could not find driver

That's strange because I've installed PDO pgsql driver on PHP 5.5.9 before and uncommented extension=pdo_mysql.so in php.ini and connection to DB works fine on my webpage.

I think the problem is that I have two different PHP versions on my server: I have folders php5 and php/5.6 in my /etc folder, which have different configurations. I have tried to delete and install php5-pgsql package, but it seems to install on the previous PHP version. I also have two different folders in my /usr/lib folder. Command php -i | grep -i pdo php -i | grep -i pdo doesn't show an installed PDO pgsql driver in console.

Is there any way to solve this problem? I think this is happening because if versions conflict.

There's not only package php/php5, but also package libapache2-mod-php. Unless you use PHP with mod_cgi, you need to update package libapache2-mod-php too, in order to have the appropriate PHP version in your web server.

As you already noted, there are several PHP config directories and files. If you want to use Postgres and PDO in version 5.6 as well, you must enable it in both config files.


On my system (Ubuntu 16.04), there are subdirectories /etc/php/7.0/cli/conf.d and /etc/php/7.0/apache2/conf.d , which both contain 20-pdo_mysql.ini

; configuration for php mysql module
; priority=20
extension=pdo_mysql.so

So you can and must configure Postgres and PDO separately for webserver and/or cli, and for each version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM