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

install on OS X: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
 
Line 316: Line 316:
Create moodle's config.php using install script
Create moodle's config.php using install script
$ /usr/bin/php admin/cli/install.php
$ /usr/bin/php admin/cli/install.php
</code>
Point browser to url you have set up locally, for example, http://mymoodle.dev.com/. If there are errors in the browser
<code>
Warning: require_once(/Users/vpp/Sites/moodle/moodle/config.php): failed to open stream: Permission denied in /Users/vpp/Sites/moodle/moodle/index.php on line 30
Fatal error: require_once(): Failed opening required 'config.php' (include_path='.:') in /Users/vpp/Sites/moodle/moodle/index.php on line 30
</code>
you might need to change the owner on just generated config.php file
<code>
$ sudo chown your_user:_www config.php
</code>
Install database. Use Moodle admin password you have set up when running admin/cli/install.php script above.
<code>
$ sudo -u _www /usr/local/bin/php admin/cli/install_database.php --lang=en --adminpass=whatever_moodle_admin_pass_you_setup --agree-license
</code>
If you are using PHP path /usr/bin/php when running above scripts and there is an error about PHP Intl extension php_intl try using /usr/local/bin/php which might be PHP installed with brew. To see what PHP you are using run
<code>
$ which php
/usr/local/bin/php
</code>
</code>




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

Latest revision as of 19:35, 16 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>

Apache configuration for /Sites folder

If you want to set up /Sites folder, which is one of possible setups, and there is no /Sites folder on your mac, create one. Also create folders for moodle and moodledata inside /Sites folder. $ cd ~ $ mkdir Sites $ cd Sites $ mkdir moodle $ mkdir moodledata Configure Apache to point to /Sites directory. Backup your httpd.conf, just in case, then open httpd.conf to make some changes $ sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.orig $ sudo vim /etc/apache2/httpd.conf Change DocumentRoot to point to /Sites folder and uncomment httpd-vhosts.conf

  1. DocumentRoot "/Library/WebServer/Documents"

DocumentRoot "/Users/mac_user_you_are_logged_in_with/Sites/" ...

  1. Virtual hosts

Include /private/etc/apache2/extra/httpd-vhosts.conf Update httpd-vhosts.conf $ sudo vim /etc/apache2/extra/httpd-vhosts.conf Pick up a url you would use locally for moodle site, for example 'mymoodle.dev.com', and add to the bottom of the httpd-vhosts.conf file <VirtualHost *:80>

   DocumentRoot "/Users/mac_user_you_are_logged_in/Sites/moodle/"
   ServerName mymoodle.dev.com
   <Directory "/Users/mac_user_you_are_logged_in/Sites/moodle/">
       Require all granted
   </Directory>

</VirtualHost> Update /etc/hosts sudo vim /etc/hosts Add a url for a local moodle site, the same as in httpd-vhosts.conf, to the bottom of /etc/hosts 127.0.0.1 mymoodle.dev.com Restart Apache sudo apachectl restart After moodle set up you should be able to point a browser to http://mymoodle.dev.com/

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 .tgz file of the version needed, for example https://download.moodle.org/download.php/stable36/moodle-latest-36.tgz, move it into /Sites folder $ mv ~/Downloads/moodle-latest-36.tgz ~/Sites/ $ tar -zxvf moodle-latest-36.tgz moodle $ cd moodle Create moodle's config.php using install script $ /usr/bin/php admin/cli/install.php Point browser to url you have set up locally, for example, http://mymoodle.dev.com/. If there are errors in the browser Warning: require_once(/Users/vpp/Sites/moodle/moodle/config.php): failed to open stream: Permission denied in /Users/vpp/Sites/moodle/moodle/index.php on line 30

Fatal error: require_once(): Failed opening required 'config.php' (include_path='.:') in /Users/vpp/Sites/moodle/moodle/index.php on line 30 you might need to change the owner on just generated config.php file $ sudo chown your_user:_www config.php Install database. Use Moodle admin password you have set up when running admin/cli/install.php script above. $ sudo -u _www /usr/local/bin/php admin/cli/install_database.php --lang=en --adminpass=whatever_moodle_admin_pass_you_setup --agree-license If you are using PHP path /usr/bin/php when running above scripts and there is an error about PHP Intl extension php_intl try using /usr/local/bin/php which might be PHP installed with brew. To see what PHP you are using run $ which php /usr/local/bin/php