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:
- 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
- Now we need to activate the extension in the php.ini, let's see php where the file is:
$ php --ini
- Edit the php.ini file and uncomment the line
extension=pdo_pgsql
- Now to check that the library is active we can run:
$ php -m | grep pdo_pgsql
$ php -i | grep pgsql
- 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
- 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/*
- 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