If you have a Apple Silicon Macs, anywhere that says /usr/local
should be replaced with /opt/homebrew
.
This is not meant for a production environment, a system holding sensitive information, or anything else of the sort. This is meant for development environments only, and makes some security tradeoffs for simple development.
We will be working in the Terminal. $
indicates the command prompt in the Terminal. You don't not include it in the comment, instead you enter what is after the $
, and press enter.
Open Terminal (in Applications > Utilities). Then enter the following at the prompt.
$ xcode-select --install
A dialog prompt will show - go through the prompts to install
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter password and follow the prompts to install.
After the install is complete, close your terminal window and open a new one.
Note that Homebrew uses /usr/local
as its base directory. So everything you might expect to be somewhere, like /etc
, /var/www
, or /var/log
, will be at /usr/local/etc
, /usr/local/var/www
, and /usr/local/var/log
respectively.
$ brew install nvm
$ brew install mysql
$ brew install postgresql@11
$ brew install php@7.3
$ brew install nginx
$ brew install --cask bbedit
Homebrew won't make certain commands available directly, if they conflict with a pre-existing system one, or some other criteria. To fix that, run:
$ brew link php@7.3
$ brew link postgresql@11
For simplicity, we will be using the text editor BBEdit. After the 30 day trial, you are still able to use it, nag for free, forever, just with a reduced feature set.
It was installed by brew, and is in your Applications folder. Open it and dismiss the purchase dialog if it shows up.
Go to the BBEdit menu, then Install Command Line Tools... and follow the prompts
Go back to the Terminal.
Open the PHP config file in BBEdit:
$ bbedit /usr/local/etc/php/7.3/php.ini
You may get a dialog confirming that you want BBEdit should have access to the file.
Find and change the following settings to these new values. Note that BBEdit's find dialog starts with Wrap around disabled. You want to enable that.
If the line starts with a ;
in the config, remove the ;
.
max_input_vars = 50000
max_execution_time = 120
post_max_size = 1024M
upload_max_filesize = 1024M
error_log = /usr/local/var/log/php.log
Save and close the file.
$ bbedit /usr/local/etc/nginx/nginx.conf
Change the listen
value to 80:
listen 80;
If you want other machines on your local network to be able to access sites on the machine, change server_name
to have the value _
:
server_name _;
Now we need to setup processing of PHP.
Find the index
directive, and add index.php before index.html:
index index.php index.html index.htm;
Now add this statement after the location / { ... }
block:
location ~ [^/]\.php(/|$) {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /usr/local/var/www/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
We need to do a couple things to make life easier. If you never plan on use PostgreSQL, you can skip this.
First, we need to startup PostgreSQL:
$ brew services run postgresql@11
First, we should create a database with the same name as your Mac username. This makes using psql easier.
$ psql -c "CREATE DATABASE $USER" postgres
Assuming that worked correctly, CREATE DATABASE
should be returned.
Now we can go and create a user for Moodle to connect with.
$ psql -c "CREATE ROLE moodle WITH SUPERUSER LOGIN PASSWORD 'm00dle'";
When this is done, you should see a CREATE ROLE
response and you should be able to just type psql
at the command prompt, and connect.
Now stop postgres:
$ brew services stop postgresql@11
We need to do a couple things to make life easier. If you never plan on use MySQL, you can skip this.
First, we need to startup MySQL:
$ brew services run mysql
Now we are going to setup the users - one for your user, for ease of use, and one for Moodle to connect with.
$ echo "CREATE USER '$USER'@'localhost';" | mysql -u root
$ echo "GRANT ALL PRIVILEGES ON * . * TO '$USER'@'localhost';" | mysql -u root
$ echo "CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'm00dle';" | mysql -u root
$ echo "GRANT ALL PRIVILEGES ON * . * TO 'moodle'@'localhost';" | mysql -u root
When this is done, you should be able to just type mysql
at the command prompt, and connect.
Now stop mysql:
$ brew services stop mysql
If you want the development environment to always be running, you can run these commands. This will start each component, and make it start on login boot.
$ brew services start mysql
$ brew services start postgresql@11
$ brew services start php@7.3
$ sudo brew services start nginx
If you just want to run it, without marking it to auto start, you can replace start with run.
Also note that nginx needs sudo to start/run because we are running it on a privileged port. If you run it on something like 8080, you won't need that.
ALTER USER 'moodle'@'localhost' IDENTIFIED WITH mysql_native_password BY 'm00dle';
echo "CREATE DATABASE moodle;" > mysql
mkdir -p /usr/local/var/moodledatas/moodle
Download moodle from github/where ever.
Go to http://localhost/moodle/
Go through install
$ brew tap danpoltawski/homebrew-mdk
$ export PATH="/usr/local/opt/python/libexec/bin:$PATH"
$ nano /usr/local/Homebrew/Library/Taps/danpoltawski/homebrew-mdk/Formula/moodle-sdk.rb
$ brew install moodle-sdk
$ sudo pip install -r /usr/local/opt/moodle-sdk/libexec/moodle-sdk/requirements.txt
$ mdk create -v 311 -i -r mindev
I have a problem with the test "zsh: command not found: ALTER" maybe I misunderstand sometime