title: PHP Unable to load dynamic library 'pdo_pgsql' in Ubuntu
body: <p>I am trying to access my postgresql database from PHP using PDO:</p>
  <pre class="lang-php prettyprint-override"><code>$pdo = new PDO($dsn, $user, $password);
  $stm = $pdo-&gt;query(&quot;SELECT * FROM books&quot;); 
  $books = $stm-&gt;fetchAll();
  </code></pre>
  <p>But I am getting this error:</p>
  <pre><code>GET /index.php - Uncaught PDOException: could not find driver in index.php:28
  </code></pre>
  <p>So far I have tried:</p>
  <ol>
  <li><code>sudo apt install php-pgsql</code></li>
  <li>Uncomment <code>extension=pdo.so</code> in <code>/etc/php/7.4/apache2/conf.d/10-pdo.ini</code></li>
  <li><code>sudo service apache2 restart</code></li>
  <li><code>sudo phpenmod pdo_pgsql</code></li>
  <li>Uncomment <code>extension=pdo_pgsql</code> in <code>/etc/php/7.4/cli/php.ini</code>.</li>
  <li><code>sudo service postgresql restart</code></li>
  </ol>
  <p>Still, I am getting the same error. I am also getting this warning at the top:</p>
  <pre><code>PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /usr/lib/php/20190902/pdo_pgsql (/usr/lib/php/20190902/pdo_pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_pgsql.so (/usr/lib/php/20190902/pdo_pgsql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0
  PHP 7.4.3 (cli) (built: Nov 25 2021 23:16:22) ( NTS )
  </code></pre>