500 (Internal Server Error)

500 (Internal Server Error)

by Kehinde Adeoya -
Number of replies: 10

Whenever I land on Moodle page and check the console I do get this error and, on clicking on the login link to display the login page, it returns

This page isn’t working

localhost is currently unable to handle this request.

HTTP ERROR 500

This is the error on the console. Please help.

jquery-3.2.1.min.js:1 POST http://localhost:8888/moodle35/lib/ajax/service.php?sesskey=JoJVIKZHUP&info=core_fetch_notifications 500 (Internal Server Error)

Loading failed for the <script> with source “http://localhost:8888/moodle35/theme/yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.js”. moodle35:32
Loading failed for the <script> with source “http://localhost:8888/moodle35/lib/javascript.php/1531169389/lib/javascript-static.js”. moodle35:32
Loading failed for the <script> with source “http://localhost:8888/moodle35/lib/javascript.php/1531169389/lib/requirejs/require.min.js”. moodle35:427
TypeError: require is not a function[Learn More] moodle35:430:1
ReferenceError: Y is not defined[Learn More] moodle35:588:14

Average of ratings: -
In reply to Kehinde Adeoya

Re: 500 (Internal Server Error)

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

Check your web server's error log. What is logged for the Error 500?

In reply to Howard Miller

Re: 500 (Internal Server Error)

by Kehinde Adeoya -

Thanks, Howard. This is the error I'm getting

[31-Aug-2018 16:40:21 Europe/Berlin] PHP Warning:  fopen(send.txt): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/config.php on line 8
[31-Aug-2018 16:40:21 Europe/Berlin] PHP Warning:  fread() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/moodle35/config.php on line 9
[31-Aug-2018 16:40:21 Europe/Berlin] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/moodle35/config.php on line 10

[31-Aug-2018 16:40:21 Europe/Berlin] PHP Notice:  Undefined property: stdClass::$libdir in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
[31-Aug-2018 16:40:21 Europe/Berlin] PHP Warning:  require_once(/externallib.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
[31-Aug-2018 16:40:21 Europe/Berlin] PHP Fatal error:  require_once(): Failed opening required '/externallib.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.15/lib/php') in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33



When I click on login to display the error log, I got this error

[31-Aug-2018 16:46:39 Europe/Berlin] PHP Warning:  fopen(send.txt): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/config.php on line 8
[31-Aug-2018 16:46:39 Europe/Berlin] PHP Warning:  fread() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/moodle35/config.php on line 9
[31-Aug-2018 16:46:39 Europe/Berlin] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/moodle35/config.php on line 10
[31-Aug-2018 16:46:39 Europe/Berlin] PHP Fatal error:  Uncaught Error: Call to undefined function redirect_if_major_upgrade_required() in /Applications/MAMP/htdocs/moodle35/login/index.php:30
Stack trace:
#0 {main}
  thrown in /Applications/MAMP/htdocs/moodle35/login/index.php on line 30



This error seems to be permanent even though it is reading it. I can read it on the console when I logged it.

[31-Aug-2018 16:40:21 Europe/Berlin] PHP Warning:  fopen(send.txt): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/config.php on line 8


These errors I'm not familiar with as I've not worked with the core Moodle files, only the config.php I have made modifications to. Please help.

[31-Aug-2018 16:40:21 Europe/Berlin] PHP Notice:  Undefined property: stdClass::$libdir in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
[31-Aug-2018 16:40:21 Europe/Berlin] PHP Warning:  require_once(/externallib.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
[31-Aug-2018 16:40:21 Europe/Berlin] PHP Fatal error:  require_once(): Failed opening required '/externallib.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.15/lib/php') in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33

In reply to Kehinde Adeoya

Re: 500 (Internal Server Error)

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Kehinde,
you should share the code you're trying to use in your config.php file since Moodle by default doesn't include anything but the configuration settings.

For Community convenience, this thread is related to:

I'd move this thread to the Developers Forum.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: 500 (Internal Server Error)

by Kehinde Adeoya -

Thanks, Matteo. This code is to switch database based on the logged in user. I write the logged the user to a file which is read here. The user is written to the file and it's picking it. The auth app is in the same MAMP server as the Moodle app.  In the config.php file, when it reads the file, it uses the credential to search for the user in the table managing users on the auth app. Then, pass the db credentials stored for the user to set the config params.

<?php 

     // require_once('send.txt');
    require_once('/Applications/MAMP/htdocs/register/DBConnect.php');

    $myFile = "send.txt";
    $fh = fopen($myFile, 'r');
    $myFileContents = fread($fh, 21);
    fclose($fh);
    $mytrimmedvalue = trim($myFileContents);

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

if ( $mytrimmedvalue != '' ) {

    $database = new dbConnect();
    $db = $database->openConnection();

    $sql = "select * from ol_users where username = '$mytrimmedvalue'";
    $user = $db->query($sql);
    $result = $user->fetchAll(PDO::FETCH_ASSOC);
    $CFG->dbtype    = 'mysqli';
    $CFG->dblibrary = 'native';
    $CFG->dbhost    = $result[0]['serverhosturl'];
    $CFG->dbname    = $result[0]['databasename'];
    $CFG->dbuser    = $result[0]['serveruser'];
    $CFG->dbpass    = '111111ade';
    $CFG->prefix    = 'mdl_';
    $CFG->dboptions = array (
      'dbpersist' => 0,
      'dbport' => '',
      'dbsocket' => '1',
      'dbcollation' => 'utf8mb4_unicode_ci',
    );

    $CFG->wwwroot   = 'http://localhost:8888/moodle35';
    // $CFG->wwwroot   = 'http://192.168.0.199:8888/moodle35';
    $CFG->dataroot  = $result[0]['moodledataurl'];
    $CFG->admin     = 'admin';

    $CFG->directorypermissions = 0777;

    require_once(dirname(__FILE__) . '/lib/setup.php');
    $database->closeConnection();
 }

In reply to Kehinde Adeoya

Re: 500 (Internal Server Error)

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've not a clue what this is trying to do and it isn't standard Moodle. 

The first problem is that it is trying to open a file called 'send.txt' that doesn't exist (or can't be read). What is that supposed to be? I can't help any more than that as this is not Moodle. 

What precisely are you trying to achieve?

In reply to Kehinde Adeoya

Re: 500 (Internal Server Error)

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Kehinde,
you can't do the kind of routing you've described above, since it is based on an user authenticated somewhere else which will land to Moodle w/o the previous user context.
The configuration routing could be done based on other context parameters depending on something like HOST, as already described in https://moodle.org/mod/forum/discuss.php?d=375239#p1512964.

Let's keep talking about your final goal in your new thread, https://moodle.org/mod/forum/discuss.php?d=375359 , since you cannot go further in hacking the Moodle config.php file here.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: 500 (Internal Server Error)

by Kehinde Adeoya -

Thanks, Matteo. Blessed to have you as my Moodle guide.

As described, I want to install a single instance of Moodle, create many institutions in Mahara, replicate many instances of Moodle database for each institution created in Mahara. Allow log in only via Mahara for students, admins and teachers will create their courses in Moodle so they should still be able to login via Moodle.

My concern is that I know for multiple Moodle instances we can chain the institutions in Mahara to it, which will allow each institution to have control over their own  Moodle installation, this is done via LTI, but this will be an overkill because of the share number of institutions we will be working with.

So my question is, is there a workaround that favors this scenario of having a single instance of Moodle, with multiple databases with each database mapped to institutions in Mahara? How will Mahara route requests to the relevant database for a user for a particular institution?

I'll be most glad if this scenario can be achieved.

In reply to Kehinde Adeoya

Re: 500 (Internal Server Error)

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

Why?

Can we take a another step back and describe to us what problem you are trying to solve?

In reply to Howard Miller

Re: 500 (Internal Server Error)

by Kehinde Adeoya -

Thanks, Howard. What I am trying to achieve is this:

This is my scenario:
1. There is a page that takes the login details of school managers who wants to join our Moodle platform. Their auth credentials are logged into our database, as well, the database config for each user.

2. If they agreed to join after running the demo, which is basically Moodle, they would be redirected to signup on Mahara and configured as an institution on it. This is because we want to have a client that can manage multiple institutions, which Mahara passes for.

3. All users created on Mahara would be synced into Moodle using LTI. Which makes them have 2 UIs for login - (Moodle and Mahara). LTI connects to instances of Moodle. This means that if I have 100 institutions in Mahara, I must have 100 instances of Moodle running. (This seems weird. It's an overkill to me, I suppose).

4. My proposed solution is to have a single Moodle that will have 100 databases (blind copy of Moodle default database setup). This means that all the users would use only a UI for authentication despite the institution. I am now looking to find a way to write a service that gets the user login details, check it against, our database that manages the auth credentials of the users. It would pull the database credentials of the user, and set it at runtime for the Moodle config.php params.
Moodle should now connect to the database based on the credentials. set for the logged in user.

This may be unstructured and not aligned with Moodle design. In a nutshell, what I want to achieve is to use a single Moodle for Multi-tenancy, with complete institution data separation. I have tried using Category of courses, yet it does not solve the problem as being a single database, complete data isolation is not achieved.

I'm sure, you being an expert already have a remedy for my concern. I'll be glad you share the better plan with me on how to achieve multi-tenancy.

Thanks a lot.