Cannot connect to local Moodle installation

Cannot connect to local Moodle installation

by willbo baggins -
Number of replies: 1

I'm trying to setup Moodle 3.1 locally on my FreeBSD box for testing purposes, and to familiarize myself with moodle in general. But, when I navigate to the locally hosted Moodle installation (localhost), I get the following message:


404 Not Found
nginx/1.10.1


I installed via the FreeBSD ports collection. However, I chose to use Nginx (not apache because nginx was already installed and working).


I've followed the following guides to a tee:

Installing and configuring nginx on FreeBSD

Nginx with Moodle

MySQL and Moodle


Below, I will detail the steps I've taken, and show what my config files contain.


I started by installing moodle31 from ports, with all the default port options:

     LDAP=off: LDAP protocol support
     MIMETEX=off: mimeTeX filter functionality support
====> Options available for the single BACKEND: you have to select exactly one of them
     MYSQL=on: MySQL database support
     PGSQL=off: PostgreSQL database support
     MSSQL=off: Microsoft SQL Server support


Then I installed and configured nginx using THIS PAGE. The results were as expected, according to the page. Navigating to "localhost" brings up the Nginx welcome page, and the php test page work fine. So far, so good.

Then I followed THIS GUIDE to set up nginx with Moodle.

Then I followed THIS GUIDE to set up MySQL and Moodle.


Now when I navigate to 'localhost' in my browser, I get the "404" error message, as described above.


However, when I change moodle config.php settings to use the default username / password combo (rather than my own user/pass combination) IE:

$CFG->dbuser    =    'username' ;
$CFG->dbpass    =    'password' ;

I get the following message from Moodle:

Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

I don't understand what is happening here.

Here is the content of my config files:

nginx.conf:

server {
            listen 80;
            server_name  localhost ;
            root /usr/local/www/moodle;
        index index.php index.html index.htm;
     
        location / {
            # First attempt to serve request as file
            try_files $uri $uri/index.php;
        }
     
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
            location ~ [^/]\.php(/|$) {
              fastcgi_split_path_info ^(.+?\.php)(/.*)$;
              if (!-f $document_root$fastcgi_script_name) {
                      return 404;
              }
     
              #free to choose between port or sock file.
              #fastcgi_pass 127.0.0.1:9000;
              fastcgi_pass unix:/var/run/php-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param   PATH_INFO       $fastcgi_path_info;
              fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
            }

            location /dataroot/ {
                internal;
                alias /usr/local/moodledata/ ;
            }
    }

Here is my Moodle config.php

<?php
$CFG = new stdClass();
$CFG->dbtype    = 'mysqli';      // 'pgsql', 'mariadb', 'mysqli', 'mssql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native';     // 'native' only at the moment
$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname    = 'moodle';     // database name, eg moodle
$CFG->dbuser    = 'moodleuser';   // your database username
$CFG->dbpass    = 'MYPASSWD';   // your database password
$CFG->prefix    = 'mdl_';       // prefix to use for all table names
$CFG->dboptions = array(
    'dbpersist' => false,       // should persistent database connections be
                                //  used? set to 'false' for the most stable
                                //  setting, 'true' can improve performance
                                //  sometimes
    'dbsocket'  => false,       // should connection via UNIX socket be used?
                                //  if you set it to 'true' or custom path
                                //  here set dbhost to 'localhost',
                                //  (please note mysql is always using socket
                                //  if dbhost is 'localhost' - if you need
                                //  local port connection use '127.0.0.1')
    'dbport'    => '',          // the TCP port number to use when connecting
                                //  to the server. keep empty string for the
                                //  default port
);
$CFG->wwwroot   = 'localhost';
$CFG->dataroot  = '/usr/local/moodledata';
$CFG->directorypermissions = 02777;
$CFG->admin = 'admin';
$CFG->xsendfile = 'X-Accel-Redirect';     // Nginx {@see http://wiki.nginx.org/XSendfile
     $CFG->xsendfilealiases = array(
         '/dataroot/' => $CFG->dataroot,
     );


Does anyone know what is going on? Or can anyone provide me with a useful link so I can work it out?


Average of ratings: -
In reply to willbo baggins

Re: Cannot connect to local Moodle installation

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I don't know anything about 'ports' or nginx. However, I just noticed one thing - you can't possibly need to mention your Moodle 'moodledata' directory in the nginx configuration. I don't think that location /dataroot/ bit should be there.

Just a 'sanity check', your Moodle definitely is installed at /usr/local/www/moodle and it does have permissions that allow nginx to actually read the files?