AWS EC2: Installation must be finished from the original IP address, sorry.

AWS EC2: Installation must be finished from the original IP address, sorry.

by Michael Milette -
Number of replies: 4
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Trying to install Moodle on AWS EC2? At one point during the Moodle installation, just before you create the admin account, you might be getting stopped in your tracks by the following message:

Installation must be finished from the original IP address, sorry.

If you are comfortable reading through source code, you may have discovered that the message is coming from the following lines:


if ($adminuser->lastip !== getremoteaddr()) {
    print_error('installhijacked', 'admin');
}

Your first instinct might be to just comment out these lines and get on with your day. However making changes to Moodle core code is rarely a good idea, especially when there is an easy and safe work around for the problem.

While commenting out the code may get you past that point in the installation, the problem will eventually come back to haunt you and you won't even realize that it is related. The problem is that Moodle getremoteaddr() function, which is used everywhere in Moodle and is responsible for identifying your IP address in Moodle, will continue to report an incorrect IP address in things like logs and may even affect the security of your website.

A better approach is to simply add the following line to your Moodle's main config.php file located in the webroot. The line should be placed anywhere between the $CFG = new stdClass(); and require_once(__DIR__ . '/lib/setup.php'); lines:

$CFG->getremoteaddrconf = 0;

This will need to be added at any point during the installation (after Moodle created your config.php file of course) up to the point when you get the error message. This setting will cause Moodle to properly identify your IP address using the Apache HTTP_X_FORWARDED_FOR server variable instead of REMOTE_ADDR and allow the installation to continue. If 0 doesn't work for you, you can try 1 or even 2.

While I have not tried the following myself, you may alternatively be able to add that line to a file called /local/defaults.php (create if it does not already exist).

For more information on defaults.php, see https://docs.moodle.org/dev/Local_plugins#Customised_site_defaults

This defaults.php file can be useful for setting default settings during a new installation if you include it in your Moodle fork.

Hope someone finds this information helpful.

Best regards,

Michael Milette

Average of ratings: Useful (2)
In reply to Michael Milette

Re: AWS EC2: Installation must be finished from the original IP address, sorry.

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Actually I think the line in defaults.php might be:
$defaults['moodle']['getremoteaddrconf'] = 0;  // New default for $CFG->getremoteaddrconf .
In reply to Michael Milette

Re: AWS EC2: Installation must be finished from the original IP address, sorry.

by Jerry Taylor -

I tried 1 and 0 but these didn't work.  Finally I found the value in the mysql db table was 3  


getremoteaddrconf3

I updated the value in the config.php file to 3 and it worked.  thanks for the info

Average of ratings: Useful (1)
In reply to Michael Milette

Re: AWS EC2: Installation must be finished from the original IP address, sorry.

by D56N STUDIO -

Hi there!

I'm quite new on moodle. And i have this issue on instalation:

I'm trying to install it in a subfolder in my host:

d56n.com.br/ead

But, as i'm using cloudflare, there are a fake ip, that i should using: 191.252.51.182

I had try all this 3 recomendantions:

1 - UPDATE mdl_user set lastip='191.252.51.182' where username='admin';

2 -putting the line ($CFG->getremoteaddrconf = 0;) on config.php and

$CFG->getremoteaddrconf = 3; too
3 - by creating the defaults.php with the same line above.

Any help, plz?

att,
ricardo


In reply to Michael Milette

Re: AWS EC2: Installation must be finished from the original IP address, sorry.

by Taufan Candra -

thank u very much for your solution
i experienced the very same problem
it was my first moodle installation which intended for my school LMS