cli install using proxy

cli install using proxy

by Alfrenovsky Rezinovsky -
Number of replies: 12

admin/cli/install.php doesn't have a proxy setting.

I need to automate moodle install behind proxies and when no proxy found the language pack download fails.

There's a way to force install to use a proxy or to predownload language packs and let install.php to handle them?

Average of ratings: -
In reply to Alfrenovsky Rezinovsky

Re: cli install using proxy

by Ken Task -
Picture of Particularly helpful Moodlers

Language packs have urls to zips ... right?  Couldn't you script download of lang packs via wget (it can be configured to use proxy) via that script and place them (unzip and mv) in appropriate directories right after install ... running upgrade.php should see new lang packs and install?

https://www.thegeekdiary.com/how-to-use-wget-to-download-file-via-proxy/

'SoS', Ken


In reply to Alfrenovsky Rezinovsky

Re: cli install using proxy

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
With the large warning that I've not tried this....

Don't allow Moodle to create config.php - create it yourself (all the required lines - there are only a few mandatory ones - are in config-dist.php) and then install. Your config.php is used if there is one.

But, before installing when you create it, add...

$CFG->proxyhost = '';
$CFG->proxyport = '0';
$CFG->proxytype = 'HTTP;
$CFG->proxyuser = '';
$CFG->proxypassword = '';
$CFG->proxybypass = 'localhost, 127.0.0.1';

Edit as required.
Average of ratings: Useful (1)
In reply to Howard Miller

Re: cli install using proxy

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Interesting. In a machine which has access to the Internet only through a proxy, I set an environment variable http_proxy='http://proxy.example.com:8080/' and all the CLI tools reach targets in the Internet.

I translated it to Moodle's Web proxy setup (on the GUI) as: Proxy host = proxy.example.com, Proxy port = 8080 and Proxy type = HTTP. But the site can not access the Internet. For e.g. language packs say "Unable to connect to the download server. etc.". Same with the site registration.

Then tried the following:
$CFG->proxyhost = 'proxy.example.com';
$CFG->proxyport = '8080';
$CFG->proxytype = 'HTTP;
$CFG->proxyuser = '';
$CFG->proxypassword = '';
$CFG->proxybypass = 'localhost, 127.0.0.1';

The same result. Language packages can not be reached. What am I doing wrong? Moodle release is 3.5.
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: cli install using proxy

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Possibly nothing. I didn't realise/think that http_proxy would also affect the command line PHP. But, of course, it should. I think your solution is the better one even if the $CFG proxy settings *did* work.

As I said, I've never tried it - I just thought it was worth a punt.
In reply to Howard Miller

Re: cli install using proxy

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Misunderstanding. When I said "all the CLI tools", I meant wget, curl, lynx, etc. Haven't checked the Moodle's CLI PHP scripts.

The puzzle is, although the HTTP proxy is perfectly OK for wget, curl, lynx, it does NOT help Moodle, neither set on the GUI nor entered in config.php. Entering in config.php seems to be right, since the GUI says "set in config.php" after that.
In reply to Visvanath Ratnaweera

Re: cli install using proxy

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'm imagining that the language packs are loaded by lib/filelib.php. That definitely checks $CFG->proxyhost et al. Superficially, it looks like it should work. Doesn't mean it does.

I don't have a proxy in the way to try it with.
In reply to Alfrenovsky Rezinovsky

Re: cli install using proxy

by Ken Task -
Picture of Particularly helpful Moodlers

@Alfredo

Are you getting any ideas as to solution to your problem?

Don't have an exact answer for ya, but have been looking into things
and suggest you do the same.

Just so I understand, you've already acquired the code for moodle - minus
the language packs.   How are you doing that?   git?

It's the cli install.php that is your issue .... no lang pack ... However ...

The install.php file has this in first few lines:

define('CLI_SCRIPT', true);

// extra execution prevention - we can not just require config.php here
if (isset($_SERVER['REMOTE_ADDR'])) {
    exit(1);
}

// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
    opcache_reset();

Then it gets into help .. which is worth a read because one switch is:
--lang=CODE

As a matter of fact, using install.php with switches does everything the GUI would do and with no issues when it comes to the initial admin user setup password.

The language pack however has to be pre-installed ... ie folders/files present
due to proxy.

Those could be acquired prior to pulling the trigger on cli install.php me thinks.

While the  only reference in cli install.php is a switch, am thinking that if the language packs are in place, install should complete.   Folders/files for lang pack already there.

Don't have a proxy set up where I could test, but if I did, think I'd try above.

'spirit of sharing', Ken


In reply to Ken Task

Re: cli install using proxy

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Ken, sorry for the intrusion. I have a question mark or two.

- Why are language packs necessary during the installation, specially for a CLI installation? In fact, have you tried changing the language on the first screen of Moodle (GUI) installation?

- For CLI installation admin/cli/install_database.php is better suited.

- Usually it is the Moodle admin (not the system admin) who decides on the languages used. For that Moodle should be set up for the web proxy. See the side discussion following Howard's post https://moodle.org/mod/forum/discuss.php?d=404410#p1632318.
In reply to Visvanath Ratnaweera

Re: cli install using proxy

by Ken Task -
Picture of Particularly helpful Moodlers

Intrusion?

original posting by Alfredo:
https://moodle.org/mod/forum/discuss.php?d=404410#p1632574

my posting asking Alfredo if he was making progress towards a solution
https://moodle.org/mod/forum/discuss.php?d=404410#p1632565

So if you think language packs install better suited with install_database.php then that's something for @Alredo to consider ... although I'm kinda confused by that ... the default lanaguage pack is en.  @Alfredo has said after installation and I assuming using the GUI admin interface, he says language packs desired cannot be acquired due to proxy.   The install_database.php script comments:

 * This installs Moodle into empty database, config.php must already exist.

Help on it says:

"Advanced command line Moodle database installer.
Please note you must execute this script with the same uid as apache.

Site defaults may be changed via local/defaults.php.

Options:
--lang=CODE           Installation and default site language. Default is en.
--adminuser=USERNAME  Username for the moodle admin account. Default is admin.
--adminpass=PASSWORD  Password for the moodle admin account.
--adminemail=STRING   Email address for the moodle admin account.
--agree-license       Indicates agreement with software license.
--fullname=STRING     Name of the site
--shortname=STRING    Name of the site
-h, --help            Print out this help

So yes ... apppears to be duplication when it comes to options for lang .... guess @Alfredo could do one more step as opposed to one step.

Still though ... language pack code would have to be acquired prior to use as @Alfredo has said can't reach the packs with proxy to install desired lang pack.

Dunno myself which would be better ... I don't have a proxy setup to tinker with ... just thinking outloud and trying to provide @Alfredo with a way to do what he wants to do.

There is something @Alfredo left out ... web sevice set up on his server ... which could be apache/nginx or a combo of both ... and of course what proxy set up he might have done already with the web service already.

Tangled webs we weave this days! smile

'SoS', Ken

Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: cli install using proxy

by Alfrenovsky Rezinovsky -
install_database.php allows me to already have a config.php with proxy settings.
I finally pre downloaded the lang pack using curl, put it in moodledata/lang and then launched install.php.
Finally setting the proxy using php.cfg.
I don't like to create a config.php if moodle has his own method with cfg.php. I prefer to respect the layers.

Not having proxy settings in install could be considered a bug. But needing a proxy in 2020 is a ridiculous. Pre downloading works
Average of ratings: Useful (1)
In reply to Alfrenovsky Rezinovsky

Re: cli install using proxy

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 *always* create my own config.php (copying config-dist.php). To be honest, that's what I would recommend if asked.