Search code examples
phplaravelpostgresqlwebserverpostgresql-10

Laravel Deployment : PHP Error Unable to load dynamic library 'pdo_pgsql'


I want to deploy my laravel app in ubuntu server 18 LTS. So I have install nginx postgres php. But when i try to do php artisan migrate I have this returned error :

This is the errror (a picture beacose of comande line) .

So I have verify different thing : First I can access to my data base in localhost with the postgres user. The laravel app work while database not be required.

In php.ini I have uncomment extention=pdo-pgsql; and extention=pgsql

I have install the php postgres sql extension with this command sudo apt-get install php7.2-pgsql

And this is my .env settings for database in laravel :

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5433
DB_DATABASE=THERY //I have already create the database
DB_USERNAME=postgres
DB_PASSWORD=postgres


Solution

  • So for my problem they have two solution plus a bonus

    1. If the problem come from php and you don't want to reinstall all you can follow this topic here in ask ubuntu and use this two command :
    sudo apt-get --purge remove php-common
    
    sudo apt-get install php-common php-pgsql php-cli
    
    1. If you want to correctly install php for laravel with postgresql you can use this comandes:
    #php install comande
    sudo apt-get install php-fpm openssl php-common php-curl php-json php-mbstring php-xml php-zip php-pgsql
    
    #make sure to uncomment extension=pdo_pgsql
    sudo nano /etc/php/7.2/fpm/php.ini 
    
    #restart fpm service to apply settings
    sudo systemctl restar php7.2-fpm
    

    Finally if you have an [SQLSTATE 08006 error] check if the port in .env file in your laravel app correspond to the listened port in your server (form me the used port is 5432 and not 5433)