Moodle on macOS Server (some infos & some issues...)

Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz
Number of replies: 22

Hi everybody...


As I spent a lot of time (who said "wasted" ?) trying to install/configure/upgrade Moodle on Mac Os X Server (and now, macOS Server), I thought I might write somewhere the problems I met and how I worked around some...


Of course: NO MAMP here !


There are documentation here for Mac Os X Server... but old, and maybenot addressing the pb you have right now.

Here: https://docs.moodle.org/32/en/Obsolete:Step_by_Step_Installation_on_a_Mac_OS_X_Server

(for 10.5 and 10.6 ... quite old...)

and here: https://docs.moodle.org/26/en/Step_by_Step_Installation_on_a_OS_X_Mountain_Lion_Server

(for 10.8... less old, but still... old... as it's 10.12 when I'm writing this).


If you're on macOS Sierra (10.12) and you go on a moodle 3.1, for instance, your php version would be recent enough... but, if you're on a Mac Pro 2,1, 3,1, or 4,1 (2007 - 2009), you're stuck with El Capitan (10.11). It means you have to upgrade your php... and believe me, it's not *that* easy. Same thing if you're on Sierra and wanna go for moodle 3.3 or + ... you need php7.x ...


First: Apache & PHP

Get this in mind: macOS Server is NOT macOS. It means the tutos and infos you'll find on the net will not be accurate. Believe me, I spent weeks (yeah, really, weeks...) trying to figure out why all these tutos lead to a dead end.


Apache server is controlled by the server app, where you can activate php by clicking on the right box. But your php version is too old or you want to update it anyway, let's say, to php 7.1. Thing is: you CAN NOT update the built in php.


There several ways to do so, with homebrew, git, curl, etc... let's go to the terminal and then, enter this:

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1

that will install php71 in /local/

if you want to use homebrew, I'm gonna take as done that you already installed it and than, in terminal:

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install php71

that will install php71 in /local/Cellar/


If you type php -v in the terminal, it will probably tell you that you now have php 7.1, so, after that, you might think you're done... but, ahahahahaha, nope. Apple super-murphy-powa. Try to launch a phpinfo and you'll find out that the apache server is still using the built in php (5.x version). Weird ? Yup.


So now, you need to change the .conf used by the apache on macOS server... WHICH IS NOT THE SAME than macOS ! Weird ? Yupyup. It's in /Library/Server/Web/Config/apache2/  !! So, let's use the terminal again (don't modify .conf or .ini file using TextEdit or Office... you'll have permissions issues after that...) with sudo nano (or sudo pico, I don't really see the difference)

sudo nano /Library/Server/Web/Config/apache2/httpd_server_app.conf


using Ctrl + W, search for php5_module. If you have checked the php bow, in the Server app (in Web Sharing section), it's uncommented (meaning: it will be used)... if you didn't, it will be commented with a # at the beginning (meaning: not used).

So, I think you got it: comment it (if it's not) and unchecked the php box in Server app (and don't checked it ever again).


Under the php5_module line, add this one:

LoadModule php7_module /usr/local/php5-7.1.4-20170506-100436/libphp7.so

(in the case you updated with curl, previously)...

If you used homebrew... OR if you used curl but the php version was updated (which is highly likely)... the path will not be the same... doesn't matter.. just place the right path instead of /usr/local/php5-7.1.4-20170506-100436/libphp7.so

(for Homebrew, that might be something like: /usr/local/Cellar/php71/7.x.x.x/libexec/apache2/libphp7.so )


then, at the end of the .conf file, you have a block starting with IfModule php5_module... after this block, add the php7 handler:

<IfModule php7_module>  
    AddType application/x-httpd-php .php  
    <FilesMatch .php$>  
        SetHandler application/x-httpd-php  
    </FilesMatch>  
    <IfModule dir_module>  
        DirectoryIndex index.php index.html  
    </IfModule>  
</IfModule>  

then save with Ctrl + O, close the .conf file with Ctrl + X and, even if it's necessary, feel free to reboot...


You'll want to change something in the php.ini to activate OPCache and change some values (php memory, this kind of stuff, as adviced in Moodle documentation)

but beware then: the php.ini that will be used is NOT the one you might think... check that using a phpinfo. How to ?

Terminal again. Type in:

sudo nano /Library/Server/Web/Data/Sites/Default/info.php


as it probably doesn't exist, it will create one.

Type

<?php
phpinfo(); 
?>
and then save with Ctrl + O, close the file with Ctrl + X and point your browser to localhost/info.php

that should do the trick.


Anyway, you have not one, but several .ini files to check ! For instance, to activate OPCache, it's not the main .ini file (where you can find a line opcache.enable= ) where you will be able to do it... but in the php.d folder, there dozen of .ini... so, to activate POPCache, in the terminal, if you installed with curl, and if it's the same version as previously written:

sudo nano /usr/local/php5-7.1.4-20170506-100436/php.d/20-extension-opcache.ini

The path might not be the exact samething... so, check that and adapt.


Second: MySQL

Go there: https://dev.mysql.com/downloads/mysql/

and and download the Community Server for Mac ... and install it.

A lot of people will tell you to use phpMyAdmin to manage your SQL server, I don't. I'd rather use an app, as I'm doing in on my local machine. I use SequelPro to manage MySQL.


you might have a root password issue... you can fix it using this tuto:

https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/


Third: Moodle

I'd advice to use git to install moodle... It might not be the easiest way for the noob (that I am) but it helps when you want to update/upgrade.

For that, the Moodle 3.3.x documentation is here: https://docs.moodle.org/33/en/Git_for_Administrators

Basically ? Terminal again.

Type in

cd /Library/Server/Web/Data/Sites/Default/

(if your webroot is not there, then change the path accordingly)

git clone git://git.moodle.org/moodle.git

cd moodle

git branch -a

git branch --track MOODLE_33_STABLE origin/MOODLE_33_STABLE

git checkout MOODLE_33_STABLE

Everything is from the documentation... I just add this here as a way to speed the process ... but anyway, take some time to read the docs. (you know: RTFM ... this kind of stuff)


Of course, you now foresee that, nope cap'tain, it's not enough. we miss something. Permissions.

For once, I don't like using the terminal, but it's basically because I'm a permanent n00b. And everytime I can use a nice GUI that does the trick, I'm gonna use it.

I use BatChModI from Lagentesoft ... I use it to find my moodle directory and then change:

- the owner to _www

- the group to admin with Read, Write permissions

- check the box so BatChMod applies the same perm to EVERYTHING inside.

Yup, that's not subtle and I'm pretty sure a lot of geeks will burn a picture of me for doing so... But that means pictures of me will be hot, very hot... at least for 2 seconds. Not so bad, huh ? Still, it's better than I can be myself anytime !!


Now, as the php version is ok, as My SQL is installed, point your browser to

localhost/moodle/

and follow the instructions.

Place the folder moodledata OUTSIDE on the folder where your site is hosted... for security reason. By default, it's:

Library/Server/Web/Data/Sites/moodledata

Which is fine.. but you can place it on another location, or another volume....

If the installer warns you about permissions, create it by yourself and you can use BatChMod again to make this moodledata folder owner as _www


After the infos about MySQL, moodle will create a config.php ... you'll have to modify it after the whole process.

It installs and everything should be fine... It might ask you to activate OPCache if you didn't. If it says it can't create the config file, because of write access, you missed the first section with BatChMod (see up ahead)


Main problem that remains:

Everything except "site not https" . It's no pb to go on with the install... and this matter needs to be adressed, as I didn't find a proper way to make moodle worked with my ssl website (which is working fine with other website like nextcloud which need php7 and ssl as well)...


Last thing to do:

Now that's it's installed... we need to modify the config file.

Terminal:

sudo nano /Library/Server/Web/Data/Sites/Default/moodle/config.php

and in

$CFG->wwwroot   =

Change the url to the one that people will use to access it...   and then, again, Ctrl+W to save, Ctrl+X to quit.

But after that, maybe you will not be able to access it from your machine ! You need to edit your host file...


Terminal:

sudo nano /private/etc/hosts

and than, add a line with your url ... like this:

127.0.0.1       www.my-moodle-is-better-than-yours.com

and then, again, Ctrl+W to save, Ctrl+X to quit.

It will say to your browser, when you go to that fancy url, like www.my-moodle-is-better-than-yours.com , in fact, point to my localhost (aka 127.0.0.1). Of course, change the line with YOUR url.


Conclusion:

This doesn't cover the rest of the configuration (themes, plug ins, how to setup the whole stuff), the documentation is here for that.


Plus, I do NOT fancy myself as an expert on these topics (mac, php, apache, whatever...). This is mainly to gather, in one place, and for the poor souls that want to moodle on their macOS Server machine... to avoid them the weeks of pain, anger, despair and torture I went thru...

There are still things that don't work (https, for instance... I need help on that) ... and some stuff that may work on moodle linux... or in MAMP/XAMP/LAMP/PAMP/CLAMP (what ? the last one doesn't exist ? hang on !), well, it may doesn't work 100% on macOS Server...


May I add that I'm french...meaning:

- my english may need improvement

- my anger management does needs improvement

- my sense of humour sure needs improvement


So, please, don't be trump on me... (-:


평균 등급 :Useful (1)
In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Howard Miller
Core developers 사진 Documentation writers 사진 Particularly helpful Moodlers 사진 Peer reviewers 사진 Plugin developers 사진

The documentation is a Wiki... so it would be really helpful if you could add that as a new page linked to the installation instructions 윙크

In reply to Howard Miller

Re: Moodle on macOS Server (some infos & some issues...)

Marcus Green
Core developers 사진 Particularly helpful Moodlers 사진 Plugin developers 사진 Testers 사진

I'd like to second Howards comment. It looks like you have spent a great deal of time solving these problems and it would be really good if other people could benefit from it by putting some of it in the Wiki. Let us know when/if you do so we can admire/use it (I don't use the Mac but I know people who). I think you need to register a separate account to add to the Wiki. 

In reply to Marcus Green

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

Well, if you can point me to the right direction to do so, I'll be pleased (:


Cause I've checked the whole site... and even asked google... but I got no clue how to access the wiki of moodle.org ....??

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

OK, seems I found my way in...


But I'm not sure that the way I describe things...  will fit into the "corporate" form used in the docs (:

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Marcus Green
Core developers 사진 Particularly helpful Moodlers 사진 Plugin developers 사진 Testers 사진

The nice thing about a Wiki is that if anyone doesn't like the way you write it they can always change it (or indeed lump it).  Go on write in your own voice, what could go wrong 미소

In reply to Marcus Green

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

just did, yesterday night (-:


basically the same text from here, with more infos, more details, more links and some mistakes corrected....

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

I wanna add that this informations is for Capitan (10.11) Server and Sierra (10.12)  Server.... but it might be quite the same for 10.9 & 10.10 (as I started my moodle years ago on a 10.9 Server...)

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

and BTW, I still need help to make my moodle to work in HTTPS ...  right now, it's just a mess when I try to do so...

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Matt T

It's pretty simple on Apache

https://www.digicert.com/ssl-certificate-installation-apache.htm

Generate private key, generate CSR (certificate signing request), send CSR to certificate authority and install it along with the certificate


Unfortunately it's tricky to use Let's Encrypt on non-Linux platforms (which essentially gives you certificates for free). Cheap ones available from RapidSSL, GoDaddy, Comodo, etc. though.

In reply to Matt T

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

as I said, my SSL is already working....  so I already did that.

and https does work nice with my NextCloud, on the same machine... or my phpbb forum... or... etc...


But, it does not work properly with my moodle... essentially if I force https in my config, the result is I can't connect in anyway (with the message telling only HTTPS connection are allowed..blah blah) in despite of the case all setting for https are done AND that I try to connect in HTTPS.


If don't force that, when I use https, the theme sometimes works... sometimes not... pictures aren't charged... sometimes they are...


So, there might be a setting somewhere that needs to be fixed... but is that in moodle ? (of course, I read and followed the doc about https...) is that is macOS ? in the server part ?? no clue for now.

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Matt T

in despite of the case all setting for https are done AND that I try to connect in HTTPS.

I don't understand this. What is the error message you get, precisely, when you visit https://yoursite and not http://yoursite

Have you changed $CFG->wwwroot in config.php to begin with https:// and not http://?

You shouldn't really enable force https until you can actually get your site working on https.

After that you need to set up a redirect in apache - so that http requests are redirected to https. You can do that a number of ways, but my preferred way is a rewrite in your apache vhost configuration files. Plenty of material available via google to learn how to do that. 

If you are using https://www.<mysite> the following redirects should be put put in place

http://<mysite> should be redirected to https://www.<mysite>

http://www.<mysite> should be redirected to https://www.<mysite>

https://<mysite> should be redirected to https://www.<mysite>


If you use http://<mysite> (without www) - the following redirects should be put in place

http://www.<mysite> should be redirected to https://<mysite>

https://www.<mysite> should be redirected to https://<mysite>

http://<mysite> should be redirected to https://<mysite>

Then you can turn on force https, so that for some reason your redirect fails, Moodle refuses to continue unless guaranteed a secure connection.


Finally (and this is done absolutely last and after you have taken a full database dump backup - you've been warned).  you should change all references on your site to http:// to https:// to avoid mixed content problems. You use the admin screen at <yoursite>/admin/tool/replace/index.php to do this.

Bonus points afterwards is to enable HSTS, but that should only be done after a few months of running stable. 

In reply to Matt T

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

If I change nothing (no redirection or else) and I go to https://<mysite> => the login page shows up but no picture, no theme, no CSS is working. I can login and then I'm back to http://  automatically.


If I redirect my http:// to my https:// (which is easily done in the server App, in macOS server...).. the login page shows up but no picture, no theme, no CSS is working. I can login but then I got an error saying the page is not properly redirected.


If I change $CFG->wwwroot in config.php to begin with https:// and not http:// , I directly go, whatever page I try to use, to an error message saying only https:// connections are allowed. I can't login. Https:// redirection can be activated or not, it's the same. Of course, the very page with this error message, when https:// is activated, is green on every security level (no warning from firefox, like it's is used to do when the https:// is not properly set)


On the other side, my https://  redictection works without any pb, with NextCloud and my phpBB forum.


Then, I tried to change all reference in my database using the tool provided in Moodle. That doesn't change anything. There are no different behaviors after the change, than before, http or https:// ...


BTW, one thing that bothers me, on a theorical level, is the fact that one needs to change every instance in his/her database (which all risks involved by this action) to activate HTTPS... I'm not sure it's the best way to have everybody to secure their websites, which more and more necessary as times goes on... I'm hope a more friendly way will be added in the next versions...

In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Matt T
please use chrome, press F12, click console tab and expand it out.


Try load the site over HTTPS, screenshot the devtools window and post it here. Specifically, screenshot any resources which appears as red as an error


Then, I tried to change all reference in my database using the tool provided in Moodle. That doesn't change anything. 

This step is done last, after HTTPS is working properly. 

is the fact that one needs to change every instance in his/her database (which all risks involved by this action) to activate HTTPS... I'm not sure it's the best way to have everybody to secure their websites

Not really. Core components will rely upon wwwroot when generating href links, so changing that suffices. Forums, etc. still suffer from the problem where people link directly to resources without reliance on environment variables. 

Even if you migrate such sites as forums etc., you need to (or should, rather) run a script to change references to the new URL in any user content, or you will be plagued with 404 errors. You are right it is a risky operation, but that's why you take a backup and extensively test the changes. 

If you use blocks, plugins etc. that directly link to content, that's not the responsibility of the core developers. The only other option would be enforcing the non-use of direct URLs, which would not be popular.

In reply to Matt T

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

is there anyway to do that without Chrome ? I don't know if it's still the case, but there was a time it was a nice spyware... so I'd rather like not using it, nor install it.

 if it's the console, then Firefox is telling me that some mixed content (css, js, and theme) is blocked, when I tried to access the login page.

I'm in the case where I just have the moodle working on http ...and just try to access it from https://

Same thing with https://   redirection activated but in this case, if I do login, I went to the page where it tells me the webpage wasn't properly redirected and there's nothing to display at all.


Same thing with https:// in config... nothing to display except the message that only https:// are allowed.


In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Matt T
Bit of a stretch to call it spyware. Your privacy concerns re. Google may be valid, in which case Chromium is a better alternative.

I think firefox's devtools got better recently. Previously if you wanted something decent you had to use firebug extension. So it'll probably suffice.


Without a screenshot, I can't see what resources are causing mixed content issues. But almost certainly it's resources that are reliant on what is in $CFG->wwwroot. Without preceding wwwroot with https://, those resources will be loading insecurely and blocked by good browsers.

Also without wwwroot as https, you will be redirected back to http:// 


You need to change that setting first, and then look at solving the issue. Can you disable force HTTPS, then change the webroot to https, and tell us if you can browse the site with https? 

In reply to Matt T

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

As I said before

I did change that settings... and so, it gave the message that only https connections are allowed... in despite of the case everything is https....

Here's screenshot with console open, when I just add https in the url (or if https redirection is activated):

https://www.dropbox.com/s/55peu8tdmpp1jwb/with%20https%20in%20the%20url.jpg?dl=0


Here's screenshot with https in the wwwroot line (in config):

https://www.dropbox.com/s/gf2emafj0kl8wbs/with%20https%20in%20the%20config.jpg?dl=0


and there was no "force HTTPS activated" anywhere...


In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Matt T

Well the first one is clearly a mixed content error, the second one is strange though.

Do you use a reverse proxy, perhaps for SSL offloading? I notice you've got a Let's Encrypt cert, which is very easy to use on Linux but more cumbersome on OS X. 

Have you tried a different browser and cleared cache? (I'm doubtful that will do much but worth a shot.)

In reply to Matt T

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

yup.. tried on Safari and on different computers...


Yep, but for a free SSL cert, there's really no other way than Let's Encrypt...


I know that it would be better to use a Linux distrib... but I'm on Os X and I don't want to use a VM just for that, it seems to me a waste of CPU/RAM... plus, Os X is a Unix and I think the tools are here... but, I think there are few people who know how to use them.. and it seems so easy to use MAMP... or a Linux VM... or... etc..  (and I like to know what I'm using, and, if I can, master it as far as I can...)


right now, my moodle works just fine in http... I'd really like to use HTTPS but, well...


BTW, I have another tiny error. Moodle keeps telling me I'm using "utf8" for my MySQL database and that I should use "utf8mb4"... except... of course my database is in "utf8mb4" !!


In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Matt T

Sorry, just to confirm, your answer here:

Yep, but for a free SSL cert, there's really no other way than Let's Encrypt...

Do you or do you not have a reverse proxy inbetween your users and the OS X server? 

If you do, you may need to set $CFG->sslproxy = true;

In reply to Matt T

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz
Where do I find this  $CFG->sslproxy = true; ??

there no such line in my moodle config...?

reverse proxy, I'm not sure what it is, here...
In reply to Jocelyn Chappaz

Re: Moodle on macOS Server (some infos & some issues...)

Emma Richardson
Documentation writers 사진 Particularly helpful Moodlers 사진 Plugin developers 사진

Are your tables all utf8mb4?  You can switch the database but you need to update the tables too.

In reply to Emma Richardson

Re: Moodle on macOS Server (some infos & some issues...)

Jocelyn Chappaz

aaahh, I get it, there was a step missing: the change in config..... !