Installing moolde on Debian 3.1 with PostgreSQL

Installing moolde on Debian 3.1 with PostgreSQL

by Ilias Choutopoulos -
Number of replies: 10
I'm using the following

Debian Sarge 3.1
Apache2
PostgreSQL 7.3
PHP4

and the modules
lipapache2-mod-php
php4-pgsql

everything is up and running fine until i get to the part that moodle needs to connect with the database and asks for the DB details. I've created the database (moodledb17) and given rights to a user (moodleuser) to write to it. This is what I put in the fields

Type: PostGreSQL
Host: localhost (i'm sure about this one because in the config file of a previous version of moodle the name of the host was localhost)
Database: moodledb17
User: moodleuser
Pass: ********
Tables Prefix: mdl_

but I keep getting the message "We could not connect to the database you specified. Please check your database settings."

I'm sure that I got php4 working with postgresql because I added myself "extension=pgsql.so" in php.ini and reloaded the DB server. What else could it be ? mixed
Average of ratings: -
In reply to Ilias Choutopoulos

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Richard Enison -

DA,

Aside from the fact that I don't follow your reasoning about PHP working with postgresql, you might want to start with http://docs.moodle.org/en/Installation_FAQ#Error:_database_connection_failed. I presume you've looked at http://docs.moodle.org/en/Debian_GNU/Linux_installation as well as the portion of http://docs.moodle.org/en/Installing_Moodle#Creating_an_empty_database dealing with PostgreSQL.

If none of that helps, post again.

RLE

In reply to Richard Enison

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Ilias Choutopoulos -
I found somewhere in the forums that this might be caused by the fact that PHP isn't working correctly with postgresql, because the php4-pgslq module isn't active (in my case it is) or apache2 isn't running with SElinux (which i'm not sure what it is). But I guess it's ok or else it would be displaying the message "PHP has not been properly configured with the PostgreSQL extension so that it can communicate with PostgreSQL. Please check your php.ini file or recompile PHP."

I have already done all those mentioned in the links you posted. However I haven't followed this way of creating the DB ..

 # su - postgres
 > psql -c "create user moodleuser createdb;" template1
 > psql -c "create database moodle ;" -U moodleuser template1
 > psql -c "alter user moodleuser nocreatedb;" template1
 > psql -c "alter user moodleuser with encrypted password 'yourpassword';" template1
 > su - root
 # /etc/init.d/postgresql reload

but this

su - postgres
createuser -DAP moodleuser
enter user password
createdb -E utf8 -O moodleuser moodledb17

the database is created and I can connect to it using shell

The reason I haven't used the way described above is that I got an error about entering a user password on step 2 (-create database moodle...).
In reply to Ilias Choutopoulos

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Richard Enison -

DA,

As we rapidly approach the edge of my very limited area of expertise, let me just say this. I am only slightly more convinced about your PHP and database setup. It's just that the fact that you can connect to it using shell does not mean you can do so using PHP. Have you looked at the output of the phpinfo command (see http://docs.moodle.org/en/phpinfo if you don't know how to generate this)? Some of the other Moodlers who could help might like to see that output posted also. thoughtful

RLE

In reply to Richard Enison

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Ilias Choutopoulos -
The strange thing is that in phpinfo my postgresql version is 8.1 while in the server i got 7.4 installed (psql --version). Maybe that's what's causing all the trouble.


In reply to Ilias Choutopoulos

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Richard Enison -

DA,

Do I understand correctly that when you type

"psql -U moodleuser template1"

at the command line prompt you get

"Welcome to psql 7.4, the PostgreSQL interactive terminal."? surprise

If so, as a non-PostgreSQL expert (& not even a PHP expert, but I'm getting there), I can only agree that this could be the problem (or at least part of it).

I don't know whether you were the one to install either PostgreSQL or PHP. If not, perhaps you could try re-installing one or both, preferably on a different server (maybe another virtual server on the same physical machine so the environment will be the same, if that's possible), so at least you can get back to where you are now if things get worse.

Short of that, I probably should pass the torch to my superiors in this area among the Moodle community for further assistance. But if you post another problem that I might be able to help with, and no one else jumps into the thread in a reasonable time, I will attempt to do what I can.

RLE

In reply to Richard Enison

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers

I suspect this has to do with the moodleuser being a postgres only user.

By default (in Debian and Debian based distros), all local connections use 'ident sameuser' access controls (in pg_hba.conf). So unless you have a system moodleuser user and the web server is using that same user to connect to postgres (which is not the case), the access will be denied.

You need to add a line telling postgres that you want to allow 'password'-based access control (which is what Moodle uses). The order of the access lines in pg_hba.conf is important, so you need to add a line like this:

host moodledb17 moodleuser 127.0.0.1 255.255.255.255 password

(where 'moodledb17' is the db you want to use password-based access control with, and 'moodleuser' is user you want to allow to connect to that database). You need to add that line after all the lines that start with:

local [...]

and before any lines that start with:

host [...]

That should do the trick wink

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Ilias Choutopoulos -
That makes sense, I tried what you said but it's not it. There's something wrong with pgsql. These are the version details from phpinfo()

PHP Version 4.4.4-8+etch
Apache 2.2.3 (Debian)
PostgreSQL(libpq) Version 8.1.8 (however psql --version give me 7.4.16). btw is libpq related to php4_pgsql module ? If it is, then I guess phpinfo is displaying the right information.

maybe i've messed up when installing packages mixed

In reply to Ilias Choutopoulos

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers

Hummm, you said you were running Debian Sarge, but now you say you have the PHP package from Etch. Have you upgraded in the mean time?

On the other hand, having the 8.1.x client libraries (libpq) to connect to a 7.4.x server is not a problem. I'm doing exactly this on a test server without any (known) side effects.

I'd start by testing a small script like this one below, just to make sure your PHP setup is able to talk to your PG server (replace the dbname, user and password with suitable values):

<?php
$pg = pg_connect ("host=localhost dbname=moodle user=moodle password=moodle");

if (!$pg) {
    echo "Can't connect to pg\n";
} else {
    echo "OK, connections work as expected\n";
}
?>

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Installing moolde on Debian 3.1 with PostgreSQL

by jeff knaggs -
Don't forget that if you edit the php.ini and/or install new php modules, you should restart the web server so php gets re-loaded !
In reply to Ilias Choutopoulos

Re: Installing moolde on Debian 3.1 with PostgreSQL

by Claudia Arteaga -
I had the same problem. I made some changes in install.php:

I changed

if ($INSTALL['stage'] == DATABASE) {

/// different format for postgres7 by socket

if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {

$INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";

$INSTALL['dbuser'] = '';

$INSTALL['dbpass'] = '';

$INSTALL['dbname'] = '';

by:

if ($INSTALL['stage'] == DATABASE) {

/// different format for postgres7 by socket

if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {

$INSTALL['dbhost'] = $INSTALL['dbhost'];

$INSTALL['dbuser'] = $INSTALL['dbuser'];

$INSTALL['dbpass'] = $INSTALL['dbpass'];

$INSTALL['dbname'] = $INSTALL['dbname'];

It worked perfect. I'm using Moodle 1.8 under Fedora Core 6, PHP 5.1.6 and Postgres 8.1.9. Furthermore I put the line "host moodle moodleuser 127.0.0.1 255.255.255.255 password" in pg_hba.conf (this was Iñaki's suggestion and it worked )!!! I hope this can help you guys. This forum has been a great help for me. Thanx. Excuse my english blush