Knowledge blog

Fix – broken page issue after Moodle 3.x installation on Nginx web server

This article intended for the people who faces broken page issue after installing Moodle 3.x. The issue usually happens after below steps.

  1. You have installed all necessary PHP modules and database is ready.
  2. You have crossed the installation steps with all success messages from moodle installer.
  3. Now at the end in the page in which you are above to configure your super administrator details and other website basic information you see the page is broken.

You might be seeing the below error.

If that is true thenthere is nothing to worry or panic. It is specific to nginx configuration issue which can be simply solved by the steps below.

The Fix

The Moodle 3.x uses Slash arguments hence by replacing your .php location block with slash arguments compatible code could fix up the issue.

  1. Open your nginx server config file (ex: /etc/nginx/sites-available/default).
  2. Find out your PHP location block. If you don’t have that location block then just fine. Copy and add the below one there.
  3. If you already have a location block for PHP with a different configuration then replace with the below one.
location ~ [^/]\.php(/|$) {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_indexindex.php;

fastcgi_passunix:/run/php/php7.0-fpm.sock;

# Replace the above value with 127.0.0.1:9000 if you are not using socket method.

includefastcgi_params;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}
  1. Now restart your nginx service and you are done.
  2. Test your website and you see your installation loading good now.

Note: In some cases if you see any other issues that may be due to the cache, so make sure you clear the moodle cache (under moodle data folder), clear browser cache and test again.

XSendfile aka X-Accel-Redirect

This one is an optional configuration for Nginx recommended by Moodle. But this is not related to the above issue and this is just to optimize your moodle performance. In case if you are just making a test and on rush then can just leave it. Once again, this is optional.

Moodle document says “Setting Moodle and Nginx to use XSendfile functionality is a big win as it frees PHP from delivering files allowing Nginx to do what it does best, i.e. deliver files.”

Let’s add this block in your nginx config file, may be next the php location block.

location /dataroot/ {

    internal;

    alias </moodle/data/path/>; # ensure the path ends with /

}

Now go to your moodle config file which is located in the root directory of your moodle folder. Let’s open and add the below block.

$CFG->xsendfile = 'X-Accel-Redirect';

$CFG->xsendfilealiases = array(

    '/dataroot/' => $CFG->dataroot

);

Make a Nginx service restart and that’s it.

Scroll to Top