title: how to enable php pdo driver for Postgres on Ubuntu 18.04
body: <p>I installed php 7.2 and php 7.3 on Ubuntu 18.04, and created a php file to log on to and insert data into the Postgres database.  My script responded  "could not find driver."  </p>
  
  <p>Research turned up that I have to edit the php.ini files and enable the extensions for Postgres and PDO.  Below are all the extension= lines in the php.ini files.  The closest I could find are the pdo lines shown below.   </p>
  
  <pre><code>extension=pdo_pgsql
  extension=pgsql
  </code></pre>
  
  <p>So I edited the php.ini files and removed the semi-colons from each of those lines to enable them.  Then I restarted Apache2:</p>
  
  <pre><code>sudo systemctl restart apache2
  </code></pre>
  
  <p>But I still get "could not find driver."  </p>
  
  <p>This is the entire listing of extensions from the php.ini files.  Which other extensions do I need to enable to allow PDO access to Postgres?  </p>
  
  <p>php.ini 7.3</p>
  
  <pre><code>;extension=bz2
  ;extension=curl
  ;extension=fileinfo
  ;extension=gd2
  ;extension=gettext
  ;extension=gmp
  ;extension=intl
  ;extension=imap
  ;extension=interbase
  ;extension=ldap
  ;extension=mbstring
  ;extension=exif      ; Must be after mbstring as it depends on it
  ;extension=mysqli
  ;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
  ;extension=odbc
  ;extension=openssl
  ;extension=pdo_firebird
  ;extension=pdo_mysql
  ;extension=pdo_oci
  ;extension=pdo_odbc
  extension=pdo_pgsql
  ;extension=pdo_sqlite
  extension=pgsql
  ;extension=shmop
  </code></pre>
  
  <hr>
  
  <p>php.ini 7.2</p>
  
  <pre><code>;extension=bz2
  ;extension=curl
  ;extension=fileinfo
  ;extension=gd2
  ;extension=gettext
  ;extension=gmp
  ;extension=intl
  ;extension=imap
  ;extension=interbase
  ;extension=ldap
  ;extension=mbstring
  ;extension=exif      ; Must be after mbstring as it depends on it
  ;extension=mysqli
  ;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
  ;extension=odbc
  ;extension=openssl
  ;extension=pdo_firebird
  ;extension=pdo_mysql
  ;extension=pdo_oci
  ;extension=pdo_odbc
  extension=pdo_pgsql
  ;extension=pdo_sqlite
  extension=pgsql
  ;extension=shmop
  </code></pre>
  
  <p>This is the php logon script (the logon credentials are replaced with dummy values here because I can't reveal them):</p>
  
  <pre><code>&lt;?php
  
  $params = [
      'host' =&gt; '[IP Address]',
      'user' =&gt; '[username]',
      'pwd' =&gt; '[password]',
      'db' =&gt; '[dbname]'
  ];
  
  $dsn = sprintf('pgsql:host=%s;dbname=%s;user=%s;password=%s',
      $params['host'],
      $params['db'],
      $params['user'],
      $params['pwd']);
  
  try {
      $dsn = sprintf('pgsql:host=%s;dbname=%s;unix_socket=%s',
          $params['host'], $params['db'], $params['sock']);
      $opts = [PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION];
      $pdo = new PDO($dsn, $params['user'], $params['pwd'], $opts);
  } catch (PDOException $e) {
      echo $e-&gt;getMessage();
  } catch (Throwable $e) {
      echo $e-&gt;getMessage();
  }
  
  ?&gt;
  </code></pre>
  
  <p>Then I edited the two .ini files and added ".so" at the end of each of the two lines and restarted Apache2, but I still get the same error message.  </p>
  
  <p>Thanks for any ideas.  </p>