nginx / MariaDB / PHP / Aegir (MEMPÆ)
Step 1: Xcode and Homebrew
XCode is required for Homebrew to compile dnsmasq, nginx, mariadb and php.
- Download and install Xcode using the Mac App Store with the link above
(it's free, but will take a while to download if your Internet connection is slow) - Once the download has finished launch Xcode and open it's preferences, goto Downloads tab and click Install on Command Line Tools.
- Follow the installation instructions for Homebrew
Mountain Lion Fixes for Homebrew
- Let everyone know where Xcode is
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
- Install X11: Visit http://xquartz.macosforge.org/trac/wiki and download and install version 2.7.2+.
- You will need to fix the symlink it makes
$ sudo ln -s /opt/X11 /usr/X11
- Reinstall your brews
$ brew list
Add directories to your path
- Ensure /usr/local/bin occurs before /usr/bin and add /usr/local/sbin is added to your path, If you are using zsh, update .zshrc instead
$ nano ~/.bash_profile
or
$ nano ~/.zshrc - Paste the following into editor then Ctrl+X and Y to save
export PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin:/opt/local/bin
Set up email sending
- First test if you are able to email yourself
$ date | mail -s test you@youremail.com
- If you are on Mountain Lion you need to create and set the permissions for these directories first (for DP4 at least)
$ sudo mkdir /Library/Server /Library/Server/Mail /Library/Server/Mail/Data /Library/Server/Mail/Data/spool /Library/Server/Mail/Data/spool/maildrop
$ sudo chown _postfix:_postdrop /Library/Server/Mail/Data/spool/maildrop - I chose to set up gmail as my email relay (this may not be required for you though)
http://realityloop.com/blog/2011/06/05/os-x-ditching-mamp-pro-part-2-gmail-email-relay - Mountain Lion appears to have a few bugs around this at the moment, I have to launch postfix on reboot
$ sudo postfix start
Step 2: Setting up dnsmasq for local wildcard DNS
- Install dnsmasq via homebrew
$ brew install dnsmasq
- Copy and edit the default conf example
$ mkdir /usr/local/etc
$ cp /usr/local/Cellar/dnsmasq/2.61/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
$ nano /usr/local/etc/dnsmasq.conf - Update the following values as shown
resolv-file=/etc/resolv.dnsmasq.conf
address=/.ld/127.0.0.1
listen-address=127.0.0.1 - Set up downstream DNS resolver
$ sudo nano /etc/resolv.dnsmasq.conf
- Paste the following and save using CTRL + X then Y
# OpenDNS IPv6:
nameserver 2620:0:ccd::2
nameserver 2620:0:ccc::2
# Google IPv6:
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
# OpenDNS:
nameserver 208.67.222.222
nameserver 208.67.220.220
# Google:
nameserver 8.8.8.8
nameserver 8.8.4.4 - Copy the launch daemon so dnsmasq runs on startup, and launch it now
$ sudo cp /usr/local/Cellar/dnsmasq/2.61/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
$ sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist - Set hostname as it's required for sane default in aegir setup, we chose rl.ld for Realityloop Local Development you can use something else instead of rl but it needs to end in .ld
$ sudo scutil --set HostName rl.ld
- Open your System Preferences, then click on Network, then for each of your interfaces (Wi-Fi & Ethernet), click on Advanced, click on DNS and finally click on the + symbol at the bottom of the left hand-side panel and set 127.0.0.1 as your only DNS Server
Step 3: Install nginx
nginx (pronounced “engine-x”) is a Web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage.
- Unless this is a fresh install of OS X you need to ensure Apache doesn't load on startup
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
- We can add some 3rd party extensions here as well (this list item is optional, if you don't want these extensions just skip to the next list item)
$ curl -s -L -o /tmp/nginx-upload-progress.tar.gz https://github.com/masterzen/nginx-upload-progress-module/tarball/v0.9.0 && mkdir /tmp/nginx-upload-progress && tar zxpf /tmp/nginx-upload-progress.tar.gz --strip-components 1 -C /tmp/nginx-upload-progress && rm /tmp/nginx-upload-progress.tar.gz
$ curl -s -L -o /tmp/nginx-fair.tar.gz http://github.com/gnosek/nginx-upstream-fair/tarball/master && mkdir /tmp/nginx-fair && tar zxpf /tmp/nginx-fair.tar.gz --strip-components 1 -C /tmp/nginx-fair && rm /tmp/nginx-fair.tar.gzNow one giant line of sed regex that will edit the Homebrew formula for nginx to add the additional compile options that we need. Make sure it all gets entered as one line.
$ sed -i '-default' 's/\([[:space:]]*\['\''--\)\(with-webdav\)\('\'',[[:space:]]*"\)\(Compile with support for WebDAV module\)\("\]\)/\1\2\3\4\5,%\1with-realip\3Compile with support for RealIP module\5,%\1with-gzip_static\3Compile with support for Gzip Static module\5,%\1with-uploadprogress\3Compile with support for Upload Progress module\5,%\1with-fair\3Compile with support for Fair module\5,%\1with-mp4\3Compile with support for MP4 module\5,%\1with-flv\3Compile with support for FLV module\5,%\1with-stub_status\3Compile with support for Stub Status module\5/; s/\([[:space:]]* args << "--\)\(with-http_dav_module\)\(" if ARGV.include? '\''--with-\)\(webdav\)\('\''.*\)/\1\2\3\4\5%\1with-http_realip_module\3realip\5%\1with-http_gzip_static_module\3gzip_static\5%\1add-module=\/tmp\/nginx-upload-progress\3uploadprogress\5%\1add-module=\/tmp\/nginx-fair\3fair\5%\1with-http_mp4_module\3mp4\5%\1with-http_flv_module\3flv\5%\1with-http_stub_status_module\3stub_status\5/; y/%/\n/' $(brew --prefix)/Library/Formula/nginx.rb
Now we'll install Nginx with our new build options and extensions and start it.
$ brew install nginx --with-realip --with-gzip_static --with-mp4 --with-flv --with-stub_status --with-uploadprogress --with-fair
$ [ $? -eq 0 ] && rm -rf /tmp/nginx-upload-progress /tmp/nginx-fair
$ mkdir -vp $(brew --prefix nginx)/var/{microcache,log,run} - If you didn't use the above to install extra nginx extensions run this, otherwise skip this command
$ brew install nginx
- Once nginx is compiled, backup the default nginx config
$ mv /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.bak
- Download our config as follows
$ curl http://realityloop.com/sites/realityloop.com/files/uploads/nginx.conf_.txt > /usr/local/etc/nginx/nginx.conf
- Edit the config to set your username, replace [username] on the third line with your own username, hit Ctrl+X and Y to save
$ nano /usr/local/etc/nginx/nginx.conf
- Make nginx log files visible in Console app
$ sudo mkdir /var/log/nginx
- Create the following directorty to stop “"/var/lib/nginx/speed" failed (2: No such file or directory)” error
$ sudo mkdir /var/lib/nginx
Step 4: MariaDB
MariaDB is a community-developed branch of the MySQL database, the impetus being the community maintenance of its free status under GPL, as opposed to any uncertainty of MySQL license status under its current ownership by Oracle.
The intent also being to maintain high fidelity with MySQL, ensuring a "drop-in" replacement capability with library binary equivalency and exacting matching with MySQL APIs and commands. It includes the XtraDB storage engine as a replacement for InnoDB.
- Still in the ‘Terminal app’, type the following command
$ brew install gnu-sed (to address Mountain Lion DP4 bug)
$ brew install mariadb --use-llvm - Once compilation has finished unset TMPDIR
unset TMPDIR
- Then mysql_install_db
$ mysql_install_db
- but don't follow any more of the prompts just now or you will run into problems, we'll do the rest later.
Step 5: Install the homebrew version of php
- Execute the brew install process using hombrew-alt php brew file
$ brew tap josegonzalez/homebrew-php
$ brew install php53 --with-mysql --with-fpm
$ brew install php53-xhprof
$ brew install php53-xdebug
$ brew install php53-uploadprogress - Edit the php.ini
$ nano /usr/local/etc/php/5.3/php.ini
Search for the extenstions section by using CTRL + W and typing: extension=php_zip.dll
extension="/usr/local/Cellar/php53-xhprof/0.9.2/xhprof.so"
extension="/usr/local/Cellar/php53-uploadprogress/1.0.3.1/uploadprogress.so"
zend_extension="/usr/local/Cellar/php53-xdebug/2.2.0/xdebug.so" - Edit the php-fpm.conf file
$ nano /usr/local/etc/php/5.3/php-fpm.conf
- Add the following line below ;pid = run/php-fpm.pid
pid = /usr/local/var/run/php-fpm.pid
- Update the user and group section as follows
user = _www
group = _www - Remove the ; from the start of the following lines then save using Ctrl+X then Y
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 5
pm.max_requests = 500 - Make our log file visible in Console app
$ sudo ln -s /usr/local/Cellar/php53/5.3.13/var/log/php-fpm.log /var/log/nginx/php-fpm.log
- Set your timezone in php.ini http://www.php.net/manual/en/timezones.php
$ nano /usr/local/etc/php/5.3/php.ini
- I added the follwing under the ;date.timezone = line
date.timezone = Australia/Melbourne
- And updated the Memory limit as follows, then saved with Ctrl+X then Y
memory_limit = 256M
Step 6: Service Launch Daemons
This is so everything runs automatically on startup
- Nginx needs to run as root for port 80 so do the following
$ sudo cp /usr/local/Cellar/nginx/1.2.2/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/
$ sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist - Edit the plist
$ sudo nano /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
Remove the following 2 groups of text and save your changes using Ctrl+X then Y
<key>KeepAlive</key>
<true/><key>UserName</key>
<string>yourusername</string>Start nginx
$ launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
- Make a directory for the rest of our launch daemons
$ mkdir -p ~/Library/LaunchAgents
- Copy the LaunchDaemon to load mariadb on boot into place and start it now
$ cp /usr/local/Cellar/mariadb/5.3.5/homebrew.mxcl.mariadb.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist - Copy php launch daemon and start it
$ cp /usr/local/Cellar/php53/5.3.13/homebrew-php.josegonzalez.php53.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php53.plist - Complete the mariaDB setup
$ sudo /usr/local/Cellar/mariadb/5.3.5/bin/mysql_secure_installation
- Answer the prompts as follows, replace [password] with a password of your own chosing
Enter current password for root (enter for none): [Enter]
Set root password? [Y/n] y
New password: [password]
Re-enter new password: [password]
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Step 7: Drush and Aegir
Your in the home stretch now!
- Install wget so Drush will work properly (need to do this on Mountain Lion)
$ brew install wget
- Make a few small changes required for this to work properly
$ sudo mkdir /var/aegir
$ sudo chown `whoami` /var/aegir
$ sudo chgrp staff /var/aegir
$ sudo dscl . append /Groups/_www GroupMembership `whoami` - Allow your user to restart nginx, be sure to replace [username] with your own username.
$ sudo -i
$ echo "[username] ALL=NOPASSWD: /usr/local/sbin/nginx" >> /etc/sudoers
$ exit - Create a symbolic link to aegir configuration
$ sudo ln -s /var/aegir/config/nginx.conf /usr/local/etc/nginx/aegir.conf
- Manually Install Drush and Aegir components
If you want to use drush 4.6 (we recommend Drush 5 though)$ brew tap BrianGilbert/homebrew-drush
To install aegir with Drush 4 remember to replace client_email in the last command with your own email address$ brew install drush46
$ drush dl --destination=/users/`whoami`/.drush drush_make-6.x
$ drush dl --destination=/users/`whoami`/.drush provision-6.x
$ drush hostmaster-install --aegir_root='/var/aegir' --root='/var/aegir/hostmaster-6.x-1.9' --http_service_type=nginx --client_email=email@domain.comTo install aegir with Drush 5 remember to replace client_email in the last command with your own email address
$ brew install drush
$ drush dl --destination=/users/`whoami`/.drush provision-6.x-2.x
$ drush hostmaster-install --aegir_root='/var/aegir' --root='/var/aegir/hostmaster-6.x-2.x-dev' --http_service_type=nginx --aegir_host=aegir.ld --client_email=email@domain.comRemember to copy the one time login link and set your aegir admin password.
- Remove the default platforms dir and create a symlink for so you can put your Platforms in ~/Sites/ directory
$ mkdir /Users/`whoami`/Sites
$ rmdir /var/aegir/platforms
$ ln -s /Users/`whoami`/Sites /var/aegir/platforms - Disable the forced caching in aegir (this is for local dev after all!)
$ nano /var/aegir/config/includes/global.inc
Paste the following text at the bottom of the document and save with CTRL +X then Y and return
unset($conf['cache']); // disable hardcoded caching
unset($conf['preprocess_css']); // disable hardcoded css aggregation
unset($conf['preprocess_js']); // disable hardcoded js aggregation - Open your web browser and start creating platforms and sites!
http://aegir.ld
This document was compiled by Brian Gilbert of Realityloop, if you had any issues or would like to say thanks post it in the comments of the original blog nginx / MariaDB / PHP / Aegir on Mac OS X with optional Drush 5 (works on Mountain Lion!)