PHP unable to connect to PG DBMS

PHP unable to connect to PG DBMS

by James B. Byrne -
Number of replies: 7

FreeBSD-11.0

Apache-2.4 (installed as a binary package from the ports collection)

PHP-5.6.30 (installed as a binary package from the ports collection)

Moodle-3.2 (installed as a binary package from the ports collection)

PG-9.6 (remote host)

I am moving a Moodle site from a Linux system to a FreeBSD system.  The database server host is unchanged between both installations.  On the FreeBSD host I have configured config.php to use the same credentials as those present on the existing system.  I have verified that config-dist.php is using the correct adapter:

# grep pgsql config-dist.php
$CFG->dbtype    = 'pgsql';      // 'pgsql', 'mariadb', 'mysqli', 'mssql', 'sqlsrv' or 'oci'

I have verified that PHP is configured with the correct adapter:

# php -i
. . .
PDO

PDO support => enabled
PDO drivers => mysql, pgsql
pdo_pgsql
. . .
pdo_pgsql

PDO Driver for PostgreSQL => enabled
PostgreSQL(libpq) Version => 9.3.15
Module version => 1.0.2
Revision =>  $Id: 0e858dd2051ca8c2fd3c781909a0670ab5fecd36 $
. . .

I have checked that the necessary ports are not fire-walled. I have verified on the pg dbms host that the pg_hpa.conf file has the necessary entries to permit access from the new host.  I have double checked the Apache virtual host configuration and am logging no errors.

What I see when I visit our Moodle site is this:

Error: database driver problem detected
The site administrator should verify server configuration

PHP has not been properly configured with the PGSQL extension so that it can communicate with PostgreSQL. Please check your php.ini file or recompile PHP.

I have Googled for this error and every thread I find comes back to the pgsql adaptor not being installed.  However, this cannot be the case here because I also have a Drupal web site installed on the same host and connecting to the same PG DBMS and it is working fine.  Drupal has to be using the same PHP

Any ideas of what could be wrong and how to fix it?
Average of ratings: -
In reply to James B. Byrne

Re: PHP unable to connect to PG DBMS

by Moodle Admin -

Hosting company can give you access to different versions of php. So drupal can use the php where pgsql module has been installed but moodle may use different version of php that pgsql module has not been installed/enabled. Please double check the drupal and moodle php versions if they are different then enable pgsql module in php for moodle.

In reply to Moodle Admin

Re: PHP unable to connect to PG DBMS

by James B. Byrne -

1.  There is no hosting company.  This is a company host running FreeBSD that has Apache-2.4 confined to a jail. 


2. There are three separate sites being served by a single Apache service inside that jail.  That Apache service has php enabled.  There only one PHP installed and that is v.5.6.  As shown in the phpinfo extract the PHP pgsql extension is installed and enabled.

3. Moodle and Drupal are sharing the same web server instance so I cannot fathom how a different PHP could be used for each. Drupal also connects to the same PGSQL host as Moodle.

In reply to James B. Byrne

Re: PHP unable to connect to PG DBMS

by Ken Task -
Picture of Particularly helpful Moodlers

Was the Moodle on the Linux box a 3.2?  or is/was it an older version?   IF the latter, what version?

The recommended way to migrate (one server to another) is transfer a full site backup (the parts/pieces - sqldump, tar ball of code, tar ball of data directory) and restore manually.   So what's the current version of Moodle on the Linux box?   The only items in config.php you would need to change would be related to paths and wwwroot (new server has a different IP/FQDN).   As well as ownerships/permissions per the new OS for the apache user/group.

Get that running first.

Not sure what this does:

Moodle-3.2 (installed as a binary package from the ports collection)

Is that how the Drupal of which you spoke was installed?

And what does an Apache Jail mean for a FreeBSD box?

Have you checked apache error logs ... or whatever special logging a jailed apache on FreeBSD might have?

'spirit of sharing', Ken

In reply to Ken Task

Re: PHP unable to connect to PG DBMS

by James B. Byrne -
In reply to James B. Byrne

Re: PHP unable to connect to PG DBMS

by Ken Task -
Picture of Particularly helpful Moodlers

Hmmm ... blank ... totally blank ... response.   Moodle glitch/hickup or issues with responding or totally frustrated?

'spirit of sharing', Ken

In reply to Ken Task

Re: PHP unable to connect to PG DBMS

by James B. Byrne -

moodle glitch I guess.  This is what went out according to my Sent folder:

On Sat, January 28, 2017 20:38, Ken Task (via Moodle.org) wrote:
>
> Moodle in English -> Forums -> Installing and upgrading help -> PHP
> unable to
> connect to PG DBMS
> https://moodle.org/mod/forum/discuss.php?d=346553#p1397736
> Re: PHP unable to connect to PG DBMS
> by Ken Task - Saturday, 28 January 2017, 8:07 PM
> ---------------------------------------------------------------------
> Was the Moodle on the Linux box a 3.2?  or is/was it an older
> version?  
> IF the latter, what version?
>
> The recommended way to migrate (one server to another) is transfer a
> full site backup (the parts/pieces - sqldump, tar ball of code,
> tar ball of data  directory) and restore manually.

The DBMS is unchanged as it resides on a different host. Therefore an
sqldump is pointless as I would be dumping from and restoring to the
exact same database on the same host.  The data was moved and restored
from a tarball.  The code comes from the binary install of drupal.

>
> So what's the current version of  Moodle on the Linux box?
2.6.11


> The only items in config.php you would need to change would be
> related to paths and wwwroot (new server has a
> different IP/FQDN).   As well as ownerships/permissions per
> the new OS for the apache user/group.
>
> Get that running first.
>

That is done and Moodle starts without error. But it will not connect
to the DBMS.

> Not sure what this does:
>
> _Moodle-3.2 (installed as a binary package from the ports collection)_
>

FreeBSD has a utility called 'pkg' which acts in a manner similar to
'yum' and 'apt' in that it handles the installation and updating of
various application packages built for FreeBSD.

> Is that how the Drupal of which you spoke was installed?

Yes, wherever possible I employ the native package manager to handle
installation and updating of application packages.

>
> And what does an _Apache Jail_ mean for a FreeBSD box?

A jail on a FreeBSD is similar to a chroot environment for specific
applications.

>
> Have you checked apache error logs ... or whatever special logging a
> jailed apache on FreeBSD might have?
>

Yes I have checked the error logs. Apache is showing nothing untoward. 
The Moodle application is failing at the point that it tries to make a
connection to the DBMS. The error message itself might be spurious as
something else may be blocking the connection that the error handling
routine is not anticipating. Nonetheless, I have to work from the
assumption that what Moodle is reporting is the actual problem.


In reply to James B. Byrne

Re: PHP unable to connect to PG DBMS

by Ken Task -
Picture of Particularly helpful Moodlers

Postgres like MySQL/MariaDB in that DB users are granted privs.  There is also a host setting in non Postgres DB servers.  Now I know those shouldn't have changed in Postgres as you are just upgrading the code, but ...   what of privs and host settings for the new Moodle DB user, DB, etc. instance?

Also, believe Moodle recommends a path for upgrades from lower versions to highest version.

A 2.6.x, for example would need to go to a 2.7.highest first and then one could march it to 3.2.highest.

Probably many changes between 2.6.x and 3.2.highest.

Have seen errors reported in Moodle that were not quite accurate ... a little misleading.   So are there Postgres logs that you could check?

'spirit of sharing', Ken