error/An error occurred whilst communicating with the server

error/An error occurred whilst communicating with the server

by Marc Mathys -
Number of replies: 8

Upgraded Debian GNU/Linux 9.13 (stretch) and it installed PHP 8.  Tried to update moodle to 3.10 from 3.8. Read that 3.11 is required for PHP 8.  Loaded PHP 7.4 and switched to it on the server.  Tried to start Moodle from the browser and got the above error.  Using MariaDB which seems to work.

Warning: session_start(): open(/var/lib/mysql/www/moodledata/sessions/sess_bmcaqtorsvfjtib84hs44513rc, O_RDWR) failed: Permission denied (13) in /var/lib/mysql/www/html/elearning/lib/classes/session/handler.php on line 45

Warning: session_start(): Failed to read session data: files (path: /var/lib/mysql/www/moodledata/sessions) in /var/lib/mysql/www/html/elearning/lib/classes/session/handler.php on line 45

Error

error/An error occurred whilst communicating with the server
Debug info:
Error code: An error occurred whilst communicating with the server
$a contents:
Stack trace:
  • line 131 of /lib/classes/session/manager.php: core\session\exception thrown
  • line 111 of /lib/classes/session/manager.php: call to core\session\manager::start_session()
  • line 804 of /lib/setup.php: call to core\session\manager::start()
  • line 32 of /config.php: call to require_once()
  • line 30 of /index.php: call to require_once()

Thanks so much for any help.  Marc


Average of ratings: -
In reply to Marc Mathys

Re: error/An error occurred whilst communicating with the server

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

It looks like PHP's session_start() is failing because it cannot access the session file in Moodledata. So check that the permissions for Moodledata are correct. This is probably a case of chown -R www-data /path/to/moodledata – assuming www-data is the user PHP scripts are run as – and configuring SELinux if enabled.

But… it looks like your Moodledata is in /var/lib/mysql. That's a strange and probably wrong place for this! MySQL (or MariaDB) tends to be strict about permissions in its own directories. You've also got the Moodle source code in /var/lib/mysql/www/html/elearning which again is a strange place for this. On my CentOS servers I'd put the Moodle source code in /var/www/moodle and the Moodledata in /var/www/moodledata.

In reply to Leon Stringer

Re: error/An error occurred whilst communicating with the server

by Marc Mathys -
Moodledata is in var/www and the source code is in var/www/html/elearning.
<?php // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'localhost';
$CFG->dbname = 'elearning';
$CFG->dbuser = 'elearningUser';
$CFG->dbpass = '**************';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => '',
'dbsocket' => '',
'dbcollation' => 'utf8mb4_general_ci',
);

$CFG->wwwroot = 'https://set.online.uni-marburg.de/elearning';
$CFG->dataroot = '/var/www/moodledata';
$CFG->admin = 'admin';

$CFG->directorypermissions = 0777;

@error_reporting(E_ALL | E_STRICT);
@ini_set('display_errors', '1');
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;

require_once(__DIR__ . '/lib/setup.php');

header('X-Frame-Options: GOFORIT');

// header always set X-Frame-Options "sameorigin";

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
In reply to Marc Mathys

Re: error/An error occurred whilst communicating with the server

by Marc Mathys -
Thanks for the help


In reply to Marc Mathys

Re: error/An error occurred whilst communicating with the server

by Marc Mathys -
I changed the owner and group name on /moodledata to www-data and it still fails but differently


In reply to Marc Mathys

Re: error/An error occurred whilst communicating with the server

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Everything – the PHP session storage directory and the error – still looks the same.

Moodledata is still in /var/lib/mysql:

Crop of Marc's error showing session file path: /var/lib/mysql/www/moodledata/...

The error and stack trace are the same as before:

error/An error occurred whilst communicating with the server

The user and group owner is user mysql and not www-data or apache.

Crop of Marc's file permission screenshot

In config.php the $CFG->dataroot = '/var/www/moodledata' looks correct and should store sessions in /var/www/moodledata/sessions. But for some reason PHP is using /var/lib/mysql/www/moodledata/sessions for session storage.

What directory is the web server configured to use for the DocumentRoot for this site? Is that config.php definitely in DocumentRoot?

Can you tell us the web server, normally Apache or Nginx?

In reply to Leon Stringer

Re: error/An error occurred whilst communicating with the server

by Marc Mathys -
Apache, Yes I changed the user and. group owner of moodledata to www-data based upon the last comment. The config.php is in html/elearning.  What directory is the web server configured to use for the DocumentRoot for this site?   Not sure how to check.  Thanks again.

There is no config file in /var/www/html.


In reply to Marc Mathys

Re: error/An error occurred whilst communicating with the server

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

DocumentRoot defines the directory containing the website's source code. So with DocumentRoot /var/www/html if you had a file called /var/www/html/elearning/marc.html containing:

<h1>Test message</h1>

Then if you went to https://yourdomain/elearning/marc.html that file should get loaded. You can try this to help find where content is being served from. (This is basic web server stuff, nothing to do with Moodle).

So if you then put the Moodle source code in /var/www/html/elearning then this is the directory that contains config.php and is where the Moodle site is loaded from.

But the errors you've shared show that the Moodle source code is being loaded from /var/lib/mysql/www/html/elearning, for example:

Permission denied (13) in /var/lib/mysql/www/html/elearning/lib/classes/session/handler on line 45

This says to me that on your server is a web server configured with DocumentRoot /var/lib/mysql/www/html and there's a config.php in /var/lib/mysql/www/html/elearning/config.php. Other possible explanations could be that there's some "chroot jail" or containerisation in use, or that there's another web server process configured differently to Apache (only one process could actually serve content on port 80 for HTTP and port 443 HTTPS).

In reply to Leon Stringer

Re: error/An error occurred whilst communicating with the server

by Marc Mathys -
It is now working. I added /elearning in the apache default file and it fixed it. So many thanks. I am back up. We have 400 students, so this was a very big deal. Marc