Adrián
Adrián

Reputation: 11

Installing php8.2-pgsql in Codespaces doesn't work first time and workaround to solve it. Should I have done something different?

I'm using Codespaces to develop my project but for some reason I've had a lot of problems to install the pdo_pgsql driver to use Postgress with my symfony project.

Finally, I've found a solution that I've already applied in different codespaces and it works... but I don't understand why it happens and if I'm really doing something wrong.

Here is a little howto of how I install the driver, at what point it gives error, and how I solve it... I hope that we can find out if I did something wrong or that we can help anyone else in my situation:

  1. Installing the php postgress driver in codespaces
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install php8.2-pgsql
  1. Now we need to activate the extension in the php.ini, let's see php where the file is:
$ php --ini
  1. Edit the php.ini file and uncomment the line
extension=pdo_pgsql
  1. Now to check that the library is active we can run:
$ php -m | grep pdo_pgsql
$ php -i | grep pgsql
  1. But in codespaces, for some unknown reason the library is not where PHP expects to find it... and in both cases it returns the following warning:
    PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql (/opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql: cannot open shared object file: No such file or directory), /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql.so (/opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
  1. So we have to find where the library is installed and put it where PHP expects it to be: (be careful that paths can change... look at PHP's warning where it expects it to be, and at the result of find to find it).
$ find / -name "pdo_pgsql.so" 2>/dev/null
$ cp /usr/lib/php/20220829/pdo_pgsql.so /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/
$ chmod +wx /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/*
  1. Now if we check again if it has worked, the warning has disappeared and PHP detects the library correctly:
$ php -m | grep pdo_pgsql
$ php -i | grep pgsql

Upvotes: 1

Views: 6224

Answers (1)

Joaquin Carmona
Joaquin Carmona

Reputation: 46

I had also the same problem, it looks like you just to uncomment the extension pgsql (not the pdo_pgsql extension) and install the pgsql package.

enter image description here

sudo apt-get install php8.2-pgsql

with that you will se the PDO enabled:

php info pdo section

with it, I was able to connect to pgsql db and avoid php cli error:

enter image description here

Upvotes: 1

Related Questions