Migrationg from Apache2 to NGINX Issues

Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
Number of replies: 14

I'm currently in the process of migrating Moodle access over Apache2 to NGINX.

All I want is to get rid of Apache2 & let NGINX serve in its place.

I already conquered some issues.

Now, I am confronted with the following, when accessing the Moodle page.


```

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 checked https://docs.moodle.org/310/en/Errors_FAQ#Error:_database_connection_failed, but this ain't helpful, as I'm not setting up Moodle.

Moodle is already set up & working. It's just that there is a different reverse proxy in front of it.


Now my question: in what way is the reverse proxy related to database access?

Moodle needs access to the database & not NGINX.

So, why would changing the reverse proxy change in any way, how the databae is accessed?

Database access is usually & always should be an app-only thing.


I guess PHP is breaking everything, again?

評比平均分數: -
In reply to Akito Kitsune

Re: Migrationg from Apache2 to NGINX Issues

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
> Error: Database connection failed
> > It is possible that the database is overloaded or otherwise not running properly.

Check this part in config.php:
$CFG->dbtype
$CFG->dblibrary
$CFG->dbhost
$CFG->dbname
$CFG->dbuser
$CFG->dbpass
$CFG->prefix
$CFG->dboptions = array (
'dbpersist' =>
'dbport' =>
'dbsocket' =>
'dbcollation' =>
);

> Moodle needs access to the database & not NGINX.

Well, it is the PHP. How did you set up PHP, fast-cgi, php-fpm, ...? Ref https://docs.moodle.org/en/Nginx.
In reply to Visvanath Ratnaweera

Re: Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
When I started the migration, I checked out this documentation regarding NGINX & applied what is offered in it.

However, the problem is, that this documentation does not say anything. It just tells, how the PHP part is set up. What about everything else?

That said, I can try the NGINX configuration for CentOS. Haven't tried it, yet, because the whole thing is running on Ubuntu.
In reply to Akito Kitsune

Re: Migrationg from Apache2 to NGINX Issues

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
> When I started the migration, I checked out this documentation regarding NGINX & applied what is offered in it.

Then tell us that when you open the discussion. Otherwise we will repeat what you already know.

> However, the problem is, that this documentation does not say anything.

Really, There are many posts in the past people getting Moodle going on Nginx with the help of that document. I too, start with it when I install a completely new server.

> It just tells, how the PHP part is set up. What about everything else?

What is everything else? This is about installing Moodle, the system software, the LEMP stack in this case, are requirements. Sure, if there is an issue with a particular component and somebody here knows about it, he'll help. But don't expect blank help on "everything else"!

> That said, I can try the NGINX configuration for CentOS. Haven't tried it, yet, because the whole thing is running on Ubuntu.

I don't know CentOS enough to say how much the LEMP for Moodle differs from the same on Ubuntu. But both lines are equally popular in these forums.
In reply to Visvanath Ratnaweera

Re: Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
> What is everything else? This is about installing Moodle, the system software, the LEMP stack in this case, are requirements. Sure, if there is an issue with a particular component and somebody here knows about it, he'll help. But don't expect blank help on "everything else"!

I know how to set up everything & this would've been set up, if PHP wasn't a caveman's scripting language.

I meant "everything else" like all the other parts of the `nginx.conf`. It only shows the PHP part of the NGINX conf. It does not show all the other parts of the NGINX conf. Since Moodle requires extra treatment, it should show all the information needed.
In reply to Visvanath Ratnaweera

Re: Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
Finally, a bit of progress.

YES! PHP broke it all, as always.

I changed `dbhost` from "localhost" to "127.0.0.1". Now, I get the page, but without any styles/themes.

It worked with "localhost" before, so why is PHP freaking out? Probably, just to be extra annoying.
In reply to Akito Kitsune

Re: Migrationg from Apache2 to NGINX Issues

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
It is not PHP. It is the socket which the database deamon got attached to.
In reply to Visvanath Ratnaweera

Re: Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
It is PHP. It worked before with localhost. Now, it does not. For no reason, it changed behaviour.
In reply to Visvanath Ratnaweera

Re: Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
I turned off slash arguments, since this is apparently a huge issue with PHP & Moodle around the globe.

Yet, JavaScript still won't load. The page just shows HTML.
In reply to Akito Kitsune

Re: Migrationg from Apache2 to NGINX Issues

Howard Miller發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin developers的相片
If you're using nginx then, presumably, you're using php-fpm. With Apache, were you using mod-php or php-fpm?

It's not exactly a great mystery getting PHP working with either of these web servers. It's *very* well understood so you can't be too far away. It's perfectly possible to get slasharguments working with nginx and is documented in the Moodle nginx page.

The connection to the database is nothing whatever to do with the web server. If you have it running enough to display the database connection error message then you've got nginx working - at least to a point.

Anyway - I'm completely lost where you have got to. It might help (me) if you reiterate what is working and what isn't.

PS. Your contempt for PHP is irrelevant. If you want to use Moodle then you're stuck with PHP. Nobody is forcing you. (Well, maybe they are but that's not our problem!). This sort of thing is usually followed by "the only language I know is javascript" 大笑
In reply to Howard Miller

Re: Migrationg from Apache2 to NGINX Issues

Akito Kitsune發表於
> It's not exactly a great mystery getting PHP working with either of these web servers. It's *very* well understood so you can't be too far away.

Then show me all the resources online about PHP, that explain how to get this to work. There are none. There is only the manual & extremely basic examples, which do not explain anything.
If you show me at least 3 different SUFFICIENT resources from 3 different sources, I will acknowledge my low quality search effort.

> It's perfectly possible to get slasharguments working with nginx and is documented in the Moodle nginx page.

Could you please quote, where I did not get it to work?
I have them set up since the beginning. They are working. But Moodle's PHP is not working.

After disabling slash arguments, the JavaScript related things are still not working.

> The connection to the database is nothing whatever to do with the web server. If you have it running enough to display the database connection error message then you've got nginx working - at least to a point.

If that is the case, then changing from Apache2 to NGINX and changing NOTHING about Moodle would have worked instantly, as is usually the case with any other sane language, like Go, Java/Kotlin, Rust, Ruby, etc. etc. etc.....
I have done this more than ten times in the past week & the first time it did not work is with Moodle, i.e. stone-old PHP.

> Anyway - I'm completely lost where you have got to. It might help (me) if you reiterate what is working and what isn't.

So, you are agreeing, that PHP is a failure in this case, because if it'd be well usable, it would be fairly easy to find the issue, since I supposedly, according to the documentation, only need to add the PHP snippet & everything works. 微笑

> Your contempt for PHP is irrelevant. If you want to use Moodle then you're stuck with PHP. Nobody is forcing you. (Well, maybe they are but that's not our problem!).

Where exactly did I share "contempt" regarding PHP? I had no opinion on it, because I'm not a caveman, who uses PHP in daily life.
I just noticed now, how terribly unusable it is. Truly a work from the mid 90's. Feels more like from the mid 60's, though.

> This sort of thing is usually followed by "the only language I know is javascript" big grin. 

Exactly, what I thought this whole time. "The only language I know is PHP." is coming across, when reading those snarky replies.

Until now, I thought JavaScript is one of the worst languages possible to use on the web. This experience showed me a different story.

PHP is pretty much on the same level as JavaScript or maybe even lower, because when there is an issue with JavaScript, there are at least plenty of resources online explaining & fixing all the faults JavaScript offers.
With PHP it's a desert, with a couple of questions & replies, which youngest dates are already more than 10 years old.

I wouldn't have expected Moodle to be such a pain in this regard, as I have already set up Nextcloud & other popular PHP products over the years & even though there were sometimes problems, it was never this bad. Well, except Flarum (Forum software), which was a huge pain, too, a couple of years ago. (At least Flarum worked in the end.)

Anyway, your arrogant & derogatory tone in your replies tells a lot about what kind of voices are accepted in the Moodle community. I would have never expected this to be the case for this type of software, which should be especially welcoming & helpful.
In reply to Akito Kitsune

Re: Migrationg from Apache2 to NGINX Issues

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
My friend, calm down!

Even if everything you are saying is true, your shouting completely damps your call for help. You are asking for help here, right?
In reply to Akito Kitsune

Re: Migrationg from Apache2 to NGINX Issues

Howard Miller發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin developers的相片
I know, it's frustrating when things don't work out for you.

Do you find that taking it out on people trying to help you (and not listening to their answers) usually works?

I didn't think so.

Anyway, you clearly know better than us dinosaurs. 
In reply to Howard Miller

Re: Migrationg from Apache2 to NGINX Issues

Gareth J Barnard發表於
Core developers的相片 Particularly helpful Moodlers的相片 Plugin developers的相片
Googled 'Moodle Nginx' and found https://docs.moodle.org/401/en/Nginx - which has the words "If you find that this does not work (scripts, styles, and images not loading) and that there are open() "..." failed (20: Not a directory) lines appearing in your logs: Check whether there are any directives related to static content before this block and try moving them after this block." - thus that could be the issue with only the HTML loading and not the CSS / JavaScript as they are loaded via PHP file calls, because they are both (with theme designer mode off) a cached bundle of all the CSS / JS in Moodle.

With the database issue, could be down to how Nginx is set up to translate domains into IP's, as 'localhost' is a domain requiring an entry in the 'hosts' file etc.  Whereas '127.0.0.1' can just be used on its own, and indeed I've read that it can be faster anyway as there is no 'lookup' to perform.

With PHP, its more akin to languages like 'C' and 'Java', whereas JavaScript (https://en.wikipedia.org/wiki/JavaScript#History), I couldn't find if it has an evolutionary parent, is different.  For me is more difficult and I suspect for lots of others too, which is possibly why there are lots more 'problem -> solution' web pages out there.
評比平均分數:Useful (2)