Note: You are currently viewing documentation for Moodle 3.11. Up-to-date documentation for the latest stable version of Moodle may be available here: install on OS X.

install on OS X: Difference between revisions

From MoodleDocs
No edit summary
Line 3: Line 3:
This page is for people who want to do an OSX install without using someone else's packaging.  
This page is for people who want to do an OSX install without using someone else's packaging.  
There are some warning to bear in mind.  
There are some warning to bear in mind.  
A native install of Moodle on an OSX machine is not really suitable as an internet linked live server  but it is great for testing and development. The OS X install described here is essentially the same as a Linux install and so the advice there can be applied here also Apple does not cooperate with your changes when they upgrade the OS.
A native install of Moodle on an OSX machine is not really suitable as an internet linked live server  but it is great for testing and development. The OS X install described here is essentially the same as a Linux install and so the advice there can be applied here. Also Apple does not cooperate with your changes when upgrading the OS.


Most of this work is via the cli which you can use in the ‘terminal’ application. To edit files, use nano or vi. Mostly you need to be root to edit the files so precede your editor name by sudo. e.g sudo nano /etc/apache2/httpd.conf or sudo vi /etc/apache2/httpd.conf
Most of this work is via the cli which you can use in the ‘terminal’ application. To edit files, use nano or vi (vim). Mostly you need to be root to edit the files so precede your editor name by sudo. e.g sudo nano /etc/apache2/httpd.conf or sudo vi /etc/apache2/httpd.conf


If you are doing any kind of development on an mac then consider an installation of  XCode (You can get this from the app store) which will install all sorts of odds and ends that you are likely to need now and then such as libraries for php etc.
If you are doing any kind of development on an mac then consider an installation of  XCode (you can get this from the app store) which will install all sorts of odds and ends that you are likely to need now and then such as libraries for php etc.


==Apache on Mac==
==Apache on Mac==


Since Mac OS X Yosemite , Apache and PHP come packaged with the OS, So you only need to enable PHP and install MySQL
Since Mac OS X Yosemite Apache and PHP come packaged with the OS so you only need to enable PHP and install MySQL


e.g sudo nano /etc/apache2/httpd.conf
<code>
sudo nano /etc/apache2/httpd.conf
or
sudo vim /etc/apache2/httpd.conf
</code>


==Starting Apache==
==Starting Apache==
Since Apache is already installed and you need to start it and test it works. Start apache via this command.
Since Apache is already installed you need to start it and to confirm it works. Start apache via command


<code>
sudo apachectl start
sudo apachectl start
</code>


If you want it to start on boot then issue this command
If you want apache to start on boot then issue this command


<code>
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
</code>


Test this by going to http://localhost on a browser.
Test apache by going to http://localhost in a browser. If you see a message saying "'''It Works!!'''" , then apache is working correctly.
If you see a message saying '''It Works!!''' , then apache is working correctly


In case of issues to verify that apache is running search for httpd process (with approximate output)
<code>
$ ps aux | grep httpd | grep -v grep
_www            18859  0.0  0.0  4314808  1296  ??  S    9:38AM  0:00.00 /usr/sbin/httpd -D FOREGROUND
root            18858  0.0  0.1  4314808  11516  ??  Ss    9:38AM  0:00.35 /usr/sbin/httpd -D FOREGROUND
</code>
To check port 80 with netstat (with approximate output)
<code>
$ netstat -an | grep '.80' | grep -i LISTEN
tcp46      0      0  *.80                  *.*                    LISTEN
</code>
Other apache related commands
<code>
$ tail -10 /var/log/apache2/error_log
$ lsof -i:80
$ curl http://localhost:80/server-status
$ apachectl -S
$ which -a apachectl
</code>


=Making “Sites” work (Optional)=
=Making “Sites” work (Optional)=
Line 32: Line 62:
Mac users are used to having a Sites folder which publishes a local-users web site  on http://<host url address>/~<UserName>
Mac users are used to having a Sites folder which publishes a local-users web site  on http://<host url address>/~<UserName>


<code>
cd /etc/apache2/users
cd /etc/apache2/users
</code>
edit  <username>.conf
edit  <username>.conf


with these contents. Don’t forget to change <username> for your username.
with these contents. Don’t forget to change <username> for your username.


<Directory "/Users/<username>/Sites/">
<code><Directory "/Users/<username>/Sites/">
AllowOverride All
    AllowOverride All
Options Indexes MultiViews FollowSymLinks
    Options Indexes MultiViews FollowSymLinks
Require all granted
    Require all granted
</Directory>
</Directory></code>


If there is no /Sites folder, create one and create folders for moodle and moodledata
<code>
$ cd ~
$ mkdir Sites
$ cd Sites
$ mkdir moodle
$ mkdir moodledata
</code>


=Making php etc work=
=Making php, etc. work=


in /etc/apache2/httpd.conf uncomment all the following lines
in /etc/apache2/httpd.conf uncomment all the following lines


<code>
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-userdir.conf
</code>


LoadModule userdir_module libexec/apache2/mod_userdir.soLoadModule php5_module libexec/apache2/libphp5.so
Since Moodle 3.3 minimum PHP version is 7.0.0 with PHP 7.1.x and 7.2.x also supported. If you have PHP 7 then php module would be


Include /private/etc/apache2/extra/httpd-userdir.conf
<code>LoadModule php7_module libexec/apache2/libphp7.so</code>


Restart apache for the changes to take effect
Restart apache for the changes to take effect


apachectl restart
<code>
sudo apachectl restart
</code>
 
==Apache user permissions on /moodledata folder==
The default Apache user is "_www" and so your /moodledata folder needs write permissions for the _www user.
 
<code>
sudo chown <username>:_www moodledata
</code>


==Test php.==
In the finder, choose the folder and using the get info dialogue to give _www write access to the folder.
 
==Test php==


Make a file in the root of your webfolder ( The default DocumentRoot for Mac OS X Yosemite is /Library/WebServer/Documents ) called phpinfo.php and add this content.
Make a file in the root of your webfolder ( The default DocumentRoot for Mac OS X Yosemite is /Library/WebServer/Documents ) called phpinfo.php and add this content.
  <?php phpinfo(); ?>
  <?php phpinfo(); ?>


Then, visit the site by url httpd://localhost/<your user name>/phpinfo.php
Then, visit the site by url  
 
<code>
http://localhost/<your user name>/phpinfo.php
</code>
This should give you the well known phpinfo page. The most likely error will be a page just showing the text <?php phpinfo(); ?> which means php is not working.
This should give you the well known phpinfo page. The most likely error will be a page just showing the text <?php phpinfo(); ?> which means php is not working.


Line 75: Line 132:
=Mysql=
=Mysql=


Download your version of Mysql from the Mysql site http://dev.mysql.com/downloads/mysql/
Download your version of Mysql from the Mysql site http://dev.mysql.com/downloads/mysql/ and install it!  
and install it!  
The dmg install will allow you to start or stop the MySql server from your system preferences. If you tick the option to start on boot then it may not actually start on boot. This is an on-off issue with OSX.
The dmg install will put allow you to start or stop the MySql server from your system preferences . If you tick the option to start on boot then it may not actually start on boot. This is an on-off issue with OSX.


If you are not running OSX server then you will probably need to install Mysql again if Apple issue an upgrade of Yosemite.
If you are not running OSX Server then you will probably need to install Mysql again if Apple issues an upgrade of Yosemite.


dmg installed MySQL is in
<code>
$ ls /usr/local/mysql/
</code>


The default Apache user is "_www" and so your moodledata folder needs write permissions for the _www user.
After MySQL dmg installation if there is an issue with the MySQL PATH when mysql commands are run, add PATH to .bash_profile (if you are using bash)
<code>
$ mysql --version
-bash: mysql: command not found
$
$ vim ~/.bash_profile
</code>


sudo chown <username>:_www moodledata
Add path to mysql at the end of .bash_profile file you opened to edit
<code>
export PATH="${PATH}:/usr/local/mysql/bin"
</code>
 
Reload .bash_profile
<code>
$ . ~/.bash_profile
$ mysql --version
mysql  Ver 8.0.13 for macos10.14 on x86_64 (MySQL Community Server - GPL)
</code>


In the finder, choose the folder and using the get info dialogue to give _www write access to the folder.
Start/stop/restart mysql
<code>
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart
</code>


Connect to MySQL command line
<code>
$ mysql -u root -p
</code>


Create moodle MySQL user, database and grant privileges
<code>
mysql> CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'moodle';
Query OK, 0 rows affected (0.03 sec)
mysql> SELECT User, Host FROM mysql.user;
mysql> CREATE DATABASE moodle;
Query OK, 1 row affected (0.07 sec)
mysql> GRANT ALL PRIVILEGES ON moodle.* to 'moodle'@'localhost';
Query OK, 0 rows affected (0.06 sec)
mysql> FLUSH PRIVILEGES;
mysql> SHOW GRANTS;
</code>


=Using Homebrew=
=Using Homebrew=


This is an easier alternative to most of the above.
This is an easier alternative to installation of required packages. Homebrew is a package management tool like apt and yum which was created for OSX. Everything ends up in /usr/local or similar and when Apple does an upgrade, they shouldn't muck it up.
Homebrew is a package management tool like apt and yum which was created for OSX. Everything ends up in /usr/local or similar and when Apple do an upgrade, they shouldn't muck it up.
The homebrew site is at http://brew.sh  
The homebrew site is at http://brew.sh  


Start with the command
Start with the command


  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
<code>
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
or
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
</code>
 
Homebrew will download and install Command Line Tools for Xcode as part of the installation process.
 
Packages installed with Homebrew are in
<code>
$ ls /usr/local/Cellar
</code>
 
=Moodle with PostgreSQL=
PostgreSQL is one of the five databases supported by Moodle. You can use Homebrew to install PostgreSQL on OSX
<code>
$ brew install postgresql
$ ls /usr/local/Cellar/postgresql/
$ brew info postgres
</code>
 
Start/stop PostgreSQL manually
<code>
$ pg_ctl -D /usr/local/var/postgres start
$ pg_ctl -D /usr/local/var/postgres stop
$ pg_ctl -D /usr/local/var/postgres status
</code>
 
Start/stop PostgreSQL using brew
<code>
$ brew services start postgresql
$ brew services stop postgresql
</code>
 
If there is an error on brew start/stop try running
<code>
$ brew services start postgresql
Error: Service `postgresql` is not started.
 
$ brew tap gapple/services
</code>
 
Create a new database cluster (collection of databases), postgres user, start postgresql. By default user postgres will not have any login password.
<code>
$ initdb /usr/local/var/postgres/data
$ ls /usr/local/Cellar/postgresql/
$ /usr/local/opt/postgres/bin/createuser -s postgres
$ pg_ctl -D /usr/local/var/postgres start
$ psql -U postgres
</code>
 
Create a moodle user, database
<code>
postgres=# CREATE USER moodleuser WITH PASSWORD 'your_password';
CREATE ROLE
postgres=# CREATE DATABASE moodle WITH OWNER moodleuser;
CREATE DATABASE
postgres=# \l
</code>
 
PostgreSQL uses a client authentication file called 'pg_hba.conf' in PostgreSQL's 'data' folder. In this file, you'll find a list of which users are allowed to connect to which databases, the IP addresses they are allowed to connect from, and the authentication methods they can use to connect.
<code>
$ vim /usr/local/var/postgres/data/pg_hba.conf
</code>
To grant permission for Moodle to connect to a PostgreSQL server on the same machine, add the following line, changing the DATABASE and USER columns to your actual database name and the username you set up above. The METHOD field should say "password" - don't put your actual password here.
<code>
# TYPE      DATABASE    USER            CIDR-ADDRESS        METHOD
  host        moodle      moodleuser      127.0.0.1/32        password
</code>
 
=Installing Moodle using cli=
Download Moodle version, for example, https://download.moodle.org/download.php/stable36/moodle-latest-36.tgz, move it into /Sites folder
<code>
$ brew install wget
$ mv ~/Downloads/moodle-latest-36.tgz ~/Sites/
$ tar -zxvf moodle-latest-36.tgz moodle
$ cd moodle
$ /usr/bin/php admin/cli/install.php
</code>




[[Category:Installation]]
[[Category:Installation]]

Revision as of 04:12, 2 January 2019

Yosemite and above native OSX install

This page is for people who want to do an OSX install without using someone else's packaging. There are some warning to bear in mind. A native install of Moodle on an OSX machine is not really suitable as an internet linked live server but it is great for testing and development. The OS X install described here is essentially the same as a Linux install and so the advice there can be applied here. Also Apple does not cooperate with your changes when upgrading the OS.

Most of this work is via the cli which you can use in the ‘terminal’ application. To edit files, use nano or vi (vim). Mostly you need to be root to edit the files so precede your editor name by sudo. e.g sudo nano /etc/apache2/httpd.conf or sudo vi /etc/apache2/httpd.conf

If you are doing any kind of development on an mac then consider an installation of XCode (you can get this from the app store) which will install all sorts of odds and ends that you are likely to need now and then such as libraries for php etc.

Apache on Mac

Since Mac OS X Yosemite Apache and PHP come packaged with the OS so you only need to enable PHP and install MySQL

sudo nano /etc/apache2/httpd.conf or sudo vim /etc/apache2/httpd.conf

Starting Apache

Since Apache is already installed you need to start it and to confirm it works. Start apache via command

sudo apachectl start

If you want apache to start on boot then issue this command

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Test apache by going to http://localhost in a browser. If you see a message saying "It Works!!" , then apache is working correctly.

In case of issues to verify that apache is running search for httpd process (with approximate output)

$ ps aux | grep httpd | grep -v grep _www 18859 0.0 0.0 4314808 1296  ?? S 9:38AM 0:00.00 /usr/sbin/httpd -D FOREGROUND root 18858 0.0 0.1 4314808 11516  ?? Ss 9:38AM 0:00.35 /usr/sbin/httpd -D FOREGROUND

To check port 80 with netstat (with approximate output) $ netstat -an | grep '.80' | grep -i LISTEN tcp46 0 0 *.80 *.* LISTEN

Other apache related commands

$ tail -10 /var/log/apache2/error_log $ lsof -i:80 $ curl http://localhost:80/server-status $ apachectl -S $ which -a apachectl

Making “Sites” work (Optional)

Mac users are used to having a Sites folder which publishes a local-users web site on http://<host url address>/~<UserName>

cd /etc/apache2/users edit <username>.conf

with these contents. Don’t forget to change <username> for your username.

<Directory "/Users/<username>/Sites/">

   AllowOverride All
   Options Indexes MultiViews FollowSymLinks
   Require all granted

</Directory>

If there is no /Sites folder, create one and create folders for moodle and moodledata $ cd ~ $ mkdir Sites $ cd Sites $ mkdir moodle $ mkdir moodledata

Making php, etc. work

in /etc/apache2/httpd.conf uncomment all the following lines

LoadModule authz_core_module libexec/apache2/mod_authz_core.so LoadModule authz_host_module libexec/apache2/mod_authz_host.so LoadModule userdir_module libexec/apache2/mod_userdir.so LoadModule php5_module libexec/apache2/libphp5.so Include /private/etc/apache2/extra/httpd-userdir.conf

Since Moodle 3.3 minimum PHP version is 7.0.0 with PHP 7.1.x and 7.2.x also supported. If you have PHP 7 then php module would be

LoadModule php7_module libexec/apache2/libphp7.so

Restart apache for the changes to take effect

sudo apachectl restart

Apache user permissions on /moodledata folder

The default Apache user is "_www" and so your /moodledata folder needs write permissions for the _www user.

sudo chown <username>:_www moodledata

In the finder, choose the folder and using the get info dialogue to give _www write access to the folder.

Test php

Make a file in the root of your webfolder ( The default DocumentRoot for Mac OS X Yosemite is /Library/WebServer/Documents ) called phpinfo.php and add this content.

<?php phpinfo(); ?>

Then, visit the site by url http://localhost/<your user name>/phpinfo.php This should give you the well known phpinfo page. The most likely error will be a page just showing the text <?php phpinfo(); ?> which means php is not working.

php modules

To Do Template:update

Mysql

Download your version of Mysql from the Mysql site http://dev.mysql.com/downloads/mysql/ and install it! The dmg install will allow you to start or stop the MySql server from your system preferences. If you tick the option to start on boot then it may not actually start on boot. This is an on-off issue with OSX.

If you are not running OSX Server then you will probably need to install Mysql again if Apple issues an upgrade of Yosemite.

dmg installed MySQL is in $ ls /usr/local/mysql/

After MySQL dmg installation if there is an issue with the MySQL PATH when mysql commands are run, add PATH to .bash_profile (if you are using bash) $ mysql --version -bash: mysql: command not found $ $ vim ~/.bash_profile

Add path to mysql at the end of .bash_profile file you opened to edit export PATH="${PATH}:/usr/local/mysql/bin"

Reload .bash_profile $ . ~/.bash_profile $ mysql --version mysql Ver 8.0.13 for macos10.14 on x86_64 (MySQL Community Server - GPL)

Start/stop/restart mysql sudo /usr/local/mysql/support-files/mysql.server start sudo /usr/local/mysql/support-files/mysql.server stop sudo /usr/local/mysql/support-files/mysql.server restart

Connect to MySQL command line $ mysql -u root -p

Create moodle MySQL user, database and grant privileges mysql> CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'moodle'; Query OK, 0 rows affected (0.03 sec) mysql> SELECT User, Host FROM mysql.user; mysql> CREATE DATABASE moodle; Query OK, 1 row affected (0.07 sec) mysql> GRANT ALL PRIVILEGES ON moodle.* to 'moodle'@'localhost'; Query OK, 0 rows affected (0.06 sec) mysql> FLUSH PRIVILEGES; mysql> SHOW GRANTS;

Using Homebrew

This is an easier alternative to installation of required packages. Homebrew is a package management tool like apt and yum which was created for OSX. Everything ends up in /usr/local or similar and when Apple does an upgrade, they shouldn't muck it up. The homebrew site is at http://brew.sh

Start with the command

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" or $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Homebrew will download and install Command Line Tools for Xcode as part of the installation process.

Packages installed with Homebrew are in $ ls /usr/local/Cellar

Moodle with PostgreSQL

PostgreSQL is one of the five databases supported by Moodle. You can use Homebrew to install PostgreSQL on OSX $ brew install postgresql $ ls /usr/local/Cellar/postgresql/ $ brew info postgres

Start/stop PostgreSQL manually $ pg_ctl -D /usr/local/var/postgres start $ pg_ctl -D /usr/local/var/postgres stop $ pg_ctl -D /usr/local/var/postgres status

Start/stop PostgreSQL using brew $ brew services start postgresql $ brew services stop postgresql

If there is an error on brew start/stop try running $ brew services start postgresql Error: Service `postgresql` is not started.

$ brew tap gapple/services

Create a new database cluster (collection of databases), postgres user, start postgresql. By default user postgres will not have any login password. $ initdb /usr/local/var/postgres/data $ ls /usr/local/Cellar/postgresql/ $ /usr/local/opt/postgres/bin/createuser -s postgres $ pg_ctl -D /usr/local/var/postgres start $ psql -U postgres

Create a moodle user, database postgres=# CREATE USER moodleuser WITH PASSWORD 'your_password'; CREATE ROLE postgres=# CREATE DATABASE moodle WITH OWNER moodleuser; CREATE DATABASE postgres=# \l

PostgreSQL uses a client authentication file called 'pg_hba.conf' in PostgreSQL's 'data' folder. In this file, you'll find a list of which users are allowed to connect to which databases, the IP addresses they are allowed to connect from, and the authentication methods they can use to connect. $ vim /usr/local/var/postgres/data/pg_hba.conf To grant permission for Moodle to connect to a PostgreSQL server on the same machine, add the following line, changing the DATABASE and USER columns to your actual database name and the username you set up above. The METHOD field should say "password" - don't put your actual password here.

# TYPE      DATABASE    USER            CIDR-ADDRESS        METHOD
  host        moodle      moodleuser      127.0.0.1/32        password

Installing Moodle using cli

Download Moodle version, for example, https://download.moodle.org/download.php/stable36/moodle-latest-36.tgz, move it into /Sites folder $ brew install wget $ mv ~/Downloads/moodle-latest-36.tgz ~/Sites/ $ tar -zxvf moodle-latest-36.tgz moodle $ cd moodle $ /usr/bin/php admin/cli/install.php