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

smanes's avatar
Level 2

Perplexing issue with Laravel 5.8 and PostgreSQL 16.4

I have a Laravel application I built several years ago on Ubuntu 18.04 LTS. I want to upgrade it to the current 24.04.1. Because I don't trust Ubuntu's upgrade process to work across several versions I created a 24.04 install on a fresh drive, mounted it and copied critical stuff from the production drive to it. When everything works I'll clone it back to the ($$) SSD drive.

Everything passed except the Postgresql connection to this Laravel app, which has run flawlessly for years. With Postgresql 16, I get an error right off the bat.

Class 'Illuminate\Database\PostgresConnection' not found (View: /web/hrl/resources/views/home/dashboard.blade.php)

Nothing has been changed in the Laravel code or config. Here's my connection block in .env

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=hrl
DB_USERNAME=www
DB_PASSWORD=www

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

Because there are some legacy Wordpress installations running on this server I have to use PHP 7.4. However, the required mods are installed.

[PHP Modules]
...
PDO
pdo_mysql
pdo_pgsql
pgsql
...
zip
zlib

Apache is also running the PHP7.4 module.

I created a little PHP script to test PHP7's PSQL PDO and it worked fine:

<?php
    $dbh = new PDO("pgsql:dbname=hrl;host=127.0.0.1", "www", "www");
    if ($dbh) { echo "\nConnected";  }
    else { echo "\nError connecting"; }
?>

It connects fine.

I can login to PostgreSQL using psql and this account without a problem.

psql -U www -W -h 127.0.0.1 -d hrl
Password: 
Pager usage is off.
psql (16.4 (Ubuntu 16.4-0ubuntu0.24.04.2))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

hrl=> 

Given that the application runs fine on Ubuntu 18.04 and PostgreSQL 10, I've run out of ideas short of throwing gris-gris powder on chicken bones.

Does anyone have clue what I should check next?? I swear, if someone gives me a lead that helps fix this problem I'll purchase a Forever Plan on Laracasts.

Here's the full error dump.

0 likes
5 replies
Snapey's avatar

Do you have that class in your vendor folder?

1 like
smanes's avatar
Level 2

@Snapey I don't! I just assumed it was there because the Laravel site was rsync'd from the old drive, where Postgresql was happy, to the new drive. Looking at the old hierarchy it's missing there too but Postgresql ran fine there. Why would Laravel suddenly want to see that class now and, more importantly, how is it best fixed?

Snapey's avatar
Snapey
Best Answer
Level 122

@smanes on your copy, delete the vendor folder and run composer install

1 like
smanes's avatar
Level 2

@Snapey I was reluctant to try this because the installation is so old (v5.8). I deleted the /vendor directory, updated composer and ran this command:

# composer install
PHP Parse error:  syntax error, unexpected ')', expecting '|' or variable (T_VARIABLE) in /usr/share/php/Symfony/Component/Console/Application.php on line 238

Parse error: syntax error, unexpected ')', expecting '|' or variable (T_VARIABLE) in /usr/share/php/Symfony/Component/Console/Application.php on line 238

Not sure what's going on here except possibly that composer is running PHP v8 and I 'm running PHP v7.4 as the default. I did try "/usr/bin/php7.4 /usr/bin/composer" but there was no difference.

Here's the Application.php function it died on.

Here's my composer.json:

smanes's avatar
Level 2

I found the issue. The composer package in Ubuntu 24.04 defaulted to PHP 8. Reinstalling with getcomposer.org directions fixed it.

Thanks! I made good on my promise to purchase a Laracasts "Forever Plan" if I got this fixed.

Please or to participate in this conversation.