Brew local development on OSX mountain lion: Nginx mariaDB DNS sass

Start by downloading and installing XCode 4.x
Now install brew
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Mountain Lion Fixes for Homebrew
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Install X11: Visit and download and install version 2.7.2+.
and make a symlink
sudo ln -s /opt/X11 /usr/X11
Reinstall your brews
brew list
Edit your profile
nano ~/.bash_profile
Paste the following into editor then Ctrl+X and Y to save
export PATH=~/bin:/usr/local/bin:/usr/local/sbin:/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
sudo chmod 777 /Library/Server/Mail/Data/spool/maildrop
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 $(brew --prefix dnsmasq)/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
brew install bind
sudo cp $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
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 /usr/local/etc/named.conf /usr/local/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 /usr/local/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
For mavericks the resolvers are handled differently
sudo mkdir -p /etc/resolver
sudo nano /etc/resolver/ld
#add
nameserver 127.0.0.1
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
Create configuration so that the wilcard is still accesible when you are not connected to a network
mkdir /etc/resolver
nano /etc/resolver/ld
Paste the following and save using CTRL+X then Y to save:
nameserver 127.0.0.1
Revert back to your default user instead of root
exit
Set hostname as it's required for sane default in aegir setup, we chose locohost.ld for Local Development you can use something else instead of rl but it needs to end in .ld
sudo scutil --set HostName loco.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.gz
Now 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
Set your username in the downloaded config file
sed -i -e 's/\[username\]/'`whoami`'/' /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 --use-llvm --env=std
Once compilation has finished unset TMPDIR
unset TMPDIR
Then mysql_install_db
cd /usr/local/Cellar/mariadb/5.5.28/
mysql_install_db
Read the output but don't follow any more of the prompts just now or you will run into problems, we'll do the rest later. You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='./data'
You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
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 tap homebrew/dupes
in mavericks you alseo need
brew tap homebrew/versions
now continue php-53
brew install php53 --with-mysql --with-fpm --with-imap
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 (check the installed versions match the text below, and update accordingly)
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.1/xdebug.so"
Set your timezone http://www.php.net/manual/en/timezones.php, I added the follwing under the ;date.timezone = line
date.timezone = Europe/Amsterdam
And updated the Memory limit as follows, then saved with Ctrl+X then Y
memory_limit = 256M
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
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  $(brew --prefix josegonzalez/php/php53)/var/log/php-fpm.log /var/log/nginx/php-fpm.log
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 $(brew --prefix nginx)/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 $(brew --prefix mariadb)/homebrew.mxcl.mariadb.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Copy php launch daemon and start it
cp $(brew --prefix josegonzalez/php/php53)/homebrew-php.josegonzalez.php53.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php53.plist
Complete the mariaDB setup
sudo $(brew --prefix mariadb)/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
Now we need to hookup php-fpm and nginx:
 nano /usr/local/etc/nginx/php.conf
Paste and change to your needs:
fastcgi_intercept_errors on;
 
location ~ \.php$
{
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
 
    fastcgi_param PATH_INFO         $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED   $document_root$fastcgi_path_info;
    fastcgi_param QUERY_STRING      $query_string;
    fastcgi_param REQUEST_METHOD    $request_method;
    fastcgi_param CONTENT_TYPE      $content_type;
    fastcgi_param CONTENT_LENGTH    $content_length;
    fastcgi_param SCRIPT_NAME       $fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    fastcgi_param REQUEST_URI       $request_uri;
    fastcgi_param DOCUMENT_URI      $document_uri;
    fastcgi_param DOCUMENT_ROOT     $document_root;
    fastcgi_param SERVER_PROTOCOL   $server_protocol;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE   nginx;
    fastcgi_param REMOTE_ADDR       $remote_addr;
    fastcgi_param REMOTE_PORT       $remote_port;
    fastcgi_param SERVER_ADDR       $server_addr;
    fastcgi_param SERVER_PORT       $server_port;
    fastcgi_param SERVER_NAME       $server_name;
 
    fastcgi_read_timeout 600; # Set fairly high for debugging
 
    fastcgi_pass  127.0.0.1:9000; # Non-default port
    fastcgi_index index.php;
}
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.com
To 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.com
Remember 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
header('X-Accel-Expires: 0'); //disable nginx caching
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
Sources:
RealityLoop and command-tab
Configure local development
mkdir /Users/%user/www/
mkdir /Users/%user/www/sites
mkdir /Users/%user/www/conf.d>
mkdir /Users/%user/www/log
Now edit nginx.conf
nano /usr/local/etc/nginx/nginx,conf
add the path to your conf.d
include /Users/%user/www/conf.d/*.vhost
Now add a test.ld site
nano /Users/%user/www/conf.d/test.vhost
and paste
  GNU nano 2.2.6              File: test.vhost                                  
 
server
{
    listen 80;
    server_name test.ld;
    root /Users/%user/www/sites/test;
 
    access_log /Users/%user/www/log/access.log;
    error_log /Users/%user/www/log/error.log;
 
    location /
    {
        index index.php;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }
 
    include  /usr/local/etc/nginx/php.conf;
}

 

Hessen Kasselstraat 8
5615 SM Eindhoven
phone: +316-81888456