I installed php on a new Ubuntu 18.04 server for Postgres, and I have a problem with php. Here are my php 7.3 installation steps:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php]
sudo systemctl restart apache2
After installing PHP 7.3, I installed pgsql.
sudo apt install php-pgsql
sudo service apache2 reload
Next I edited the php.ini file in /etc/php/7.3/apache2 and removed the semi-colons from the following lines:
extension=pdo_pgsql
extension=pgsql
I saved the file and did sudo systemctl restart apache2.
Finally I enabled the modules:
sudo phpenmod -v 7.3 pgsql
sudo phpenmod -v 7.3 pdo_pgsql
sudo systemctl restart apache2
Then I created a script to use pdo to log on to my Postgres database (the logon credentials are replaced with placeholder values here.)
<?php
$params = [
'host' => '[IP Address]',
'user' => '[username]',
'pwd' => '[password]',
'db' => '[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 => PDO::ERRMODE_EXCEPTION];
$pdo = new PDO($dsn, $params['user'], $params['pwd'], $opts);
} catch (PDOException $e) {
echo $e->getMessage();
} catch (Throwable $e) {
echo $e->getMessage();
}
?>
But the Firefox dev console echoes back: "could not find driver."
One clue is that php 7.3 is in /etc/apache2/mods-available, but it's not in /etc/apache2/mods-enabled, which suggests that it's not enabled. But when I try phpenmod -v 7.3 php7.3.conf, I get: WARNING: Module php7.3.conf ini file doesn't exist under /etc/php/7.3/mods-available.
I've done a lot of research on this, and those are the steps to follow. Much of that research was specific to MySQL, but that shouldn't matter for PDO.
Thanks for any ideas on why I am getting the message "could not find driver."
UPDATE:
I created a script to run phpinfo():
<?php
ob_start();
phpinfo();
$info = ob_get_clean();
echo $info;
?>
but it returns only html code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
a:link {color: #009; text-decoration: none; background-color: #fff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse; border: 0; width: 934px; box-shadow: 1px 2px 3px #ccc;}
.center {text-align: center;}
.center table {margin: 1em auto; text-align: left;}
.center th {text-align: center !important;}
td, th {border: 1px solid #666; font-size: 75%; vertical-align: baseline; padding: 4px 5px;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccf; width: 300px; font-weight: bold;}
.h {background-color: #99c; font-weight: bold;}
.v {background-color: #ddd; max-width: 300px; overflow-x: auto; word-wrap: break-word;}
.v i {color: #999;}
img {float: right; bo…
jquery.min.js line 2 > eval:12:21
?
But that's not what I expected.
a2enmod php7.3<?php phpinfo(); exit;in aninfo.phpand navigate to it in your browser. You would need to usea2dismod php7.2as well to disable PHP 7.2 followed bya2enmod php7.3to switch to php 7.3 in Apache.php5you'll need to doa2dismod php5then.DSNhasunix_socketin it and yourparams['socket']is missing, can't help with that without knowing how your database server is configured. (Port or Socket)pgsql:host=%s;dbname=%s;unix_socket=%sSee: php.net/manual/en/ref.pdo-pgsql.connection.php So you would to change it to readpgsql:host=%s;dbname=%s;user=%s;password=%s