nginx / MariaDB / PHP / Aegir (MEMPÆ)

You can watch a video of this process at http://www.youtube.com/watch?v=-b81t4bX_gE

Step 1: Install the requirements for this process; Xcode and Homebrew

XCode is required for Homebrew to compile 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 run the newly downloaded ‘Install Xcode’ app which will appear in Launchpad and follow the prompts.
  • Now go back to your terminal window and type the following to install Homebrew
    $ ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
  • Download homebrew-alt so we can rebuild php with the required components
    $ git clone https://github.com/adamv/homebrew-alt.git /usr/local/LibraryAlt
  • Add /usr/local/sbin to you path
    $ nano ~/.bash_profile
  • Paste the following into editor then Ctrl+X and Y to save
    PATH=$PATH:/usr/local/sbin; export PATH

Step 2: Setting up bind

BIND or named is the most widely used DNS software on the Internet, we will be configuring this for wildcard DNS of our development TLD (Top Level Domain) and using Google DNS as secondary DNS lookup for all other requests.

Open the terminal application and enter the following:

  • become root

    $ sudo -i

  • Backup the default configuration

    $ cp /etc/named.conf /etc/named.conf.bck

  • Create the keyfile that is read by both rndc and named on startup
    $ rndc-confgen -a
  • Edit the named.conf file
    $ nano /etc/named.conf
  • Inside the “options {“ block add the following before the last }
    forwarders {
           8.8.8.8;  //Google DNS
           8.8.4.4;  //Google DNS
    };
  • Add the following just before zone "0.0.127.in-addr.arpa" IN {
    zone "ld" IN {
           type master;
           file "db.ld";
    };
  • Save your changes by hitting Ctrl+X then Y
  • Create db.ld file, we chose .ld for our TLD as it equated to local development in our minds
    $ nano /var/named/db.ld
  • Paste the following
    ld. 7200    IN       SOA     dev. root.ld. (
                 2008031801 ;    Serial
                 15      ; Refresh every 15 minutes
                 3600    ; Retry every hour
                 3000000 ; Expire after a month+
                 86400 ) ; Minimum ttl of 1 day
                 IN      NS      ld.
                 IN      MX      10 ld.

                 IN      A       127.0.0.1
    *.ld.        IN      A       127.0.0.1

  • Save your changes by hitting Ctrl+X then Y
  • Run the following commands to ensure configuration is ok
    $ named-checkconf /etc/named.conf 
    $ named-checkzone ld /var/named/db.ld
  • Set your computers network settings to use 127.0.0.1 as DNS server in System Preferences -> Network for both Wireless and Ethernet connections by clicking Advanced and selecting the DNS tab
  • Set Bind to load on startup, and load it right now
    $ launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist
  • Check setup with dig, were looking for NOERROR in the returned text
    $ dig test.ld
  • We can also test ping which should return something like the following (if not try a restart or dscacheutil -flushcache), hit Ctrl+C to cancel ping task
    $ ping test.ld
    PING test.ld (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.033 ms
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.061 ms
    64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.060 ms
  • 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
    $ scutil --set HostName rl.ld
  • Revert back to your default user instead of root
    $ exit

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
  • Optional: Edit nginx.rb homebrew installer to add --with-debug flag
    $ sudo nano /usr/local/Library/Formula/nginx.rb
  • Add the following line in the args = ["--prefix=#{prefix}", section after "--with-pcre", followed by Ctrl+X then Y to save.
    "--with-debug",
  • Still in the ‘Terminal app’, type the following 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
  • 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 mariadb
  • 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: Update php

  • Backup your original version of PHP, in the case you ever want to revert to a vanilla state. Note: You may need to repeat this step anytime you use combo updater to install OS X updates
    $ sudo mv /usr/bin/php /usr/bin/php-apple
  • Execute the brew install process using hombrew-alt php brew file
    $ brew install /usr/local/LibraryAlt/duplicates/php.rb --with-mysql --with-fpm
  • Once compilation is complete create your php-fpm config file
    $ cp /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf.default /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf
  • Create symbolic link for it in /usr/local/etc/
    $ sudo ln -s /usr/local/Cellar/php/5.3.8/etc/php-fpm.conf /usr/local/etc/php-fpm.conf
  • Edit the conf file
    $ nano /usr/local/etc/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 = 20
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    pm.max_requests = 500
  • Create directory and file for php-fpm log
    $ mkdir /usr/local/Cellar/php/5.3.8/var/log/
    $ touch /usr/local/Cellar/php/5.3.8/var/log/php-fpm.log
  • Make our log file visible in Console app
    $ sudo ln -s /usr/local/Cellar/php/5.3.8/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.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

  • Type the following into you open Terminal window
    $ sudo -i
  • Download the LaunchDaemon to load nginx on boot
    $ curl http://realityloop.com/sites/realityloop.com/files/uploads/nginx.plist_.txt > /System/Library/LaunchDaemons/org.homebrew.nginx.plist
  • Download LaunchDaemon for php-fpm
    $ curl http://realityloop.com/sites/realityloop.com/files/uploads/php-fpm.plist... > /System/Library/LaunchDaemons/org.homebrew.php-fpm.plist
  • Copy the LaunchDaemon to load mariadb on boot into place
    $ cp /usr/local/Cellar/mariadb/5.2.8/com.mysql.mysqld.plist /System/Library/LaunchDaemons/com.mysql.mysqld.plist
  • Restart your computer to enable the services Yes you really need to do this now, or the next step will not work
  • Open terminal again and type the following
    $ sudo /usr/local/Cellar/mariadb/5.2.8/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!

  • 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
  • Manually Install Drush and Aegir components
    $ export DRUSH_VERSION=7.x-4.5
    $ curl -O http://ftp.drupal.org/files/projects/drush-$DRUSH_VERSION.tar.gz
    $ gunzip -c drush-$DRUSH_VERSION.tar.gz | tar -xf -
    $ rm drush-$DRUSH_VERSION.tar.gz
  • Make Drush accesible via your path
    $ sudo ln -s ~/drush/drush /usr/local/bin/drush
  • Download drush_make and provision
    $ drush dl drush_make-6.x --destination="/users/`whoami`/.drush"
    $ drush dl provision-6.x --destination="/users/`whoami`/.drush"
  • Apply the following patch to provision until version 6.x-1.5 of aegir comes out
    http://drupalcode.org/sandbox/omega8cc/1111100.git/commit/a208ed4
  • Create symbolic link for aegir vhosts
    $ sudo ln -s /var/aegir/config/nginx.conf /usr/local/etc/nginx/aegir.conf
  • Install Hostmaster!
    $ drush hostmaster-install --aegir_root='/var/aegir' --root='/var/aegir/hostmaster-6.x-1.4' --http_service_type=nginx
  • 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
  • Open your web browser and start creating platforms and sites!
    http://aegir.ld