0

I have a Laravel 5.8, running locally on my macOS Big Sur 11.4

I checked phpinfo();, enter image description hereI see

Loaded Configuration File

/Applications/MAMP/bin/php/php7.4.12/conf/php.ini.

pdo_pgsql

I checked /Applications/MAMP/bin/php/php7.4.12/conf/php.ini. I found these, they are uncommented already.

enter image description here

It's also reflected in the phpinfo page

enter image description here


Lately, I can not run php artisan migrate successfully, I kept getting :

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')

I'm using psql not MySQL.

DB_LOCAL_CONNECTION=pgsql
DB_LOCAL_HOST=localhost
DB_LOCAL_PORT=5432
DB_LOCAL_DATABASE=dbName
DB_LOCAL_USERNAME=postgres
DB_LOCAL_PASSWORD=

Did I check the wrong file? What else should I check ?


@Tim : I added this as per your comment.

<?php

return [

    'default' => env('DB_LOCAL_CONNECTION', 'pgsql'),

    'connections' => [

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_LOCAL_HOST', '127.0.0.1'),
            'port' => env('DB_LOCAL_PORT', '5432'),
            'database' => env('DB_LOCAL_DATABASE', 'db'),
            'username' => env('DB_LOCAL_USERNAME', 'user'),
            'password' => env('DB_LOCAL_PASSWORD', '123'),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

    ]

];

@Brain

This is for you. I tried to update the CLI version to 7.3 like so, and check the ini file of that 7.3, it is enabled ... plz see steps below

brew install php@7.3
cd /usr/local/etc/php/7.3/
code php.ini


➜  7.3 cat php.ini | grep pgsql                                                                                          
extension=pdo_pgsql                                                                                                      
extension=pgsql                                                                                                          
; http://php.net/pgsql.allow-persistent                                                                                  
pgsql.allow_persistent = On                                                                                              
; http://php.net/pgsql.auto-reset-persistent                                                                             
pgsql.auto_reset_persistent = Off                                                                                        
; http://php.net/pgsql.max-persistent                                                                                    
pgsql.max_persistent = -1                                                                                                
; http://php.net/pgsql.max-links                                                                                         
pgsql.max_links = -1                                                                                                     
; http://php.net/pgsql.ignore-notice                                                                                     
pgsql.ignore_notice = 0                                                                                                  
; Unless pgsql.ignore_notice=0, module cannot log notice message.                                                        
; http://php.net/pgsql.log-notice                                                                                        
pgsql.log_notice = 0
code-8
  • 54,650
  • 106
  • 352
  • 604
  • I had a similar problem yesterday. Try using port 5433. – Alberto Valerio Sep 24 '21 at 20:34
  • It doesn't matter if the port is `5432` or `5433`, the error is saying you don't have the driver to use `pgsql`, not that it cannot connect to the database. – matiaslauriti Sep 25 '21 at 00:09
  • A possible issue is that your `default` connection isn't using your `.env` variable: `'default' => env('DB_CONNECTION', 'pgsql'),`. See how that references `DB_CONNECTION`, but yours is named `DB_LOCAL_CONNECTION`? That doesn't match. Note: Those are the default settings, you didn't show that particular setting, so it's a guess. – Tim Lewis Sep 27 '21 at 20:41
  • 1
    @TimLewis : I have this line in my `database.php` `'default' => env('DB_LOCAL_CONNECTION', 'pgsql'),` – code-8 Sep 27 '21 at 20:43
  • In a previous edit, there was a discrepancy between what `php -v` returned, and what `phpinfo` returned. One said 7.3 and the other 7.4. This could be leading to inconsistent behavior since they will use separate ini files and may have different modules enabled. Since, once again, a previous edit said this was while running migrations, I believe it will be using the cli ini file. So you may be checking the wrong place – Brian Thompson Sep 27 '21 at 20:45
  • So `php artisan migrate` use CLI php.ini ... not Web Server php.ini ? I can check both files, and make sure they're enabled in both files. – code-8 Sep 27 '21 at 20:46
  • @TimLewis Base on your doubt, I updated my post provide my database.php – code-8 Sep 27 '21 at 20:49
  • 1
    Thanks, that clears that up. It was a suspicion, but yeah, that looks ok. – Tim Lewis Sep 27 '21 at 20:50
  • Yes. So if it's truly running 7.3 on the cli I would suggest updating it to match the webserver. And then I would also check the ini file for your cli to make sure the same things are enabled. – Brian Thompson Sep 27 '21 at 20:50
  • I just updated 7.1 to 7.3. Now I will try to update to 7.4 as your suggestion. – code-8 Sep 27 '21 at 20:56
  • I can success ran `brew install php@7.4`, but CLI still show `7.3.24` – code-8 Sep 27 '21 at 21:01
  • I don't use a Mac so I don't know if this part is the same, but I have multiple versions of PHP installed currently on Ubuntu. There are commands to switch which version is enabled. There may be a command like that for you to run – Brian Thompson Sep 27 '21 at 21:03
  • Mac is unix base, what is the tool you used called ? I might able to use the same. This is driving me insane, thanks guys for your help looking into this along with me. – code-8 Sep 27 '21 at 21:08
  • https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04 – Brian Thompson Sep 27 '21 at 21:14

1 Answers1

3

You should check your php.ini file if extensions named: pdo_pgsql.so and pgsql.so are here and uncommented.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Justas
  • 71
  • 3
  • I saw these lines `extension=pgsql.so` and `extension=pdo_pgsql.so` uncommented out already. I checked in `/Applications/MAMP/bin/php/php7.4.12/conf/php.ini` Was I checking the wrong file ? – code-8 Sep 27 '21 at 20:12