Category:Mac OS X

From MoodleDocs
Revision as of 00:25, 19 August 2017 by Jocelyn Chappaz (talk | contribs) (How to set up Apache, PHP & install Moodle 3.x on macOS Server)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Docs related specifically to running Moodle under Mac OS X.


Introduction

Hi everybody... This is my first page in the Wiki, so please be nice with me. Plus, I'm used to do my teachings/tutorials (etc...) with a weird sense of humour: I don't really know how to do without.

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... I did in the forum here: [[1]]

Requirements: NO MAMP here ! Only macOS 10.11 Server or 10.12 Server. These informations will work on macOS 10.11 (Capitan) and 10.12 Sierra Server. If you don't have the Server app, it will NOT work this way. It should be the same for 10.10 Server & 10.9 Server, but I'm not able to test.

There already are documentation here for Mac Os X Server... but old, and maybenot addressing the pb you have right now. Here: [[2]] (for 10.5 and 10.6 ... quite old...)

and here: [[3]] (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 ...! As the one you got built-in is a php 5.x

About moodle, I only test it with 3.3 and 3.4 beta but I think it's safe to say it can be used with 3.1, 3.2, 3.3 and 3.4 version.

For those who wonder what's this app Terminal I'm gonna use, it allows to send Unix commands to the system. Very useful. You can find it in the Applications folder, in your hard disk.


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, because they mostly mostly talk about macOS "not server", the "normal" version. Believe me, I spent weeks (yeah, really, weeks...) trying to figure out why all these tutos lead to a dead end.

In macOS Server, the 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, right ? You want to update it anyway, let's say, to php 7.1. Thing is: you CAN NOT update the built in php. You have to install another php next to the built-in php and tell the Apache server to use this new one insteand of the old one... But the old will not be discarded... Which can lead, sometimes, to weird situations like "why this app is telling me I got php 5.x while this other one is telling me I got php 7.1.4 ?". When you know it's logical, fine. When you don't, you feel like a chicken who just finds a fork.


So, update: there several ways to do so, with homebrew, git, curl, etc... let's go with curl and 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 check, just go in the finder, type Cmd+Shift+G (Go to...) and simply type /local/ then enter. Don't do kiddy stuff in there, if you don't want your system to go haywire.

If you want to use homebrew, I'm gonna take as done that you already installed it and if you don't: [4] Homebrew install might take a moment, so don't rush that. And then, 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. (I give info about phpinfo below, for those who don't know about it)


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 permission issues after that, nasty ones !) with sudo nano (or sudo pico, I don't really see the difference).

In the Terminal:

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

using Ctrl + W, search for php5_module. If you have checked the php box, 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 more and more likely to be the case as time goes on)... 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 ) Check using Cmd+Shift+G

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 are dozen of .ini... so, to activate OPCache, 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, like you did before !


Second: MySQL

Go there: [5] 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: [6]


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: [[7]]

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 a lazy guy. Everytime I can use a nice GUI that does the trick, I'm gonna use it.

I use BatChMod from Lagentesoft: [8] I use it to find my moodle directory (probably in /Library/Server/Web/Data/Sites/Default/) 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. For both, check up ahead.


Main problem that remains:

Everything except "site not https" . It's no problem to go on with the install... but 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, terminal, agaaaain:

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

and where there's this line:

   $CFG->wwwroot   =

Change the url to the one that people will use to access it (something like http://www.my-moodle-is-better-than-yours.com/moodle) 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...


Terminaaaaaal:

   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. (Nope, there's no real moodle with url: www.my-moodle-is-better-than-yours.com.. sorry. I know you find that disappointing, but, you know, so is life...)


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 100% on moodle linux... or in MAMP/XAMP/LAMP/PAMP/CLAMP (what ? the last one doesn't exist ? hang on !), well, it may not work 100% on macOS Server.


May I add that I'm french...meaning: - my english may need improvement - my anger management does need improvement (I'm french, we go on strike and riot every time, what did you expect, huh ?) - my sense of humour sure needs improvement

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

Pages in category "Mac OS X"

The following 5 pages are in this category, out of 5 total.