openphotonet_cup_of_joe-edit

We all need a fresh start sometimes.  Over the last year I have been managing projects on WordPress, PHP and Rails.  More recently, I have been leveling up my UI skills, and learning Ember, Angular, and Node.

My laptop had started to become a bit cluttered and sluggish, from years of migrated OS installs, as well as a lack of using package managers to handle my updates.  I had used Brew a bit, but only for my rails development.  As I began experimenting and learning these new Javascript MVC’s and stumbled onto NPM, Yeoman, Grunt, and Bower, I realized what I was missing from my development process.  Time to make it happen.

I decided to document my experience, both for my own archives, and because some of the gists and articles I read were outdated. This does not contain all of the various system tweaks, bash replacements, or other customizations.

I mainly wanted to focus on getting the core installations in place, and make sure they were working.   PHP and Rails for traditional web projects and creating APIs.  MySQL and Postgres for databases.  NPM, Angular, and Ember for front end development.   I will add dependencies specific to each project, but only the basics on the system level.

The idea was to create a snapshot of my initial setup – both literally as a disk image when it was complete, as well as to provide a simple example for other front end developers looking to make the jump into the modern MVC and package manager driven development world.

One last note, I have not settled on a new virtualization platform.  I had VMWare Fusion installed previously, with a bunch of Windows VMs for testing IE.  With the release of Windows 10, it was getting a little tiresome to manage and update multiple VM images, so I have been using BrowserStack.com instead.

This also does not include any graphics or video editing apps.  I keep separate users for those environments, in order to minimize conflicts and make rebuilding easier.

So, after installing Yosemite onto a fresh new 960GB SSD drive, I was ready to rumble.

The steps that I took in order are outlined below.

  • UI Customizations – my choice tweaks to make the OSX interface a little more useful for developers
  • Xcode + Command line tools – needed to install most of this other stuff. 
  • Brew & Caskroom – Package manager for development tools and applications
  • Git – Source code version control + collaboration
  • Ruby on Rails
  • PHP
  • Mysql – world’s most popular open source database
  • Postgres – world’s most advanced open source database
  • NPM & Node.js – built on Chrome’s Javascript runtime for fast network applications
  • Angular, and Ember CLI – the leading Javascript MVC frameworks
  • Grunt, BowerYeoman – popular taskrunner, js package manager, and scaffolding combo for front end tasks

UI Customizations

# Check for software updates daily, not just once per week
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

#Use current directory as default search scope in Finder
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"

#Show Path bar in Finder
defaults write com.apple.finder ShowPathbar -bool true

# Enable the Develop menu and the Web Inspector in Safari
defaults write com.apple.Safari IncludeDevelopMenu -bool true && \
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true && \
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true && \
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true

#Show the ~/Library folder in Finder
chflags nohidden ~/Library

#Show absolute path in finder’s title bar.
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES

#Enable text copying from Quick Look
com.apple.finder QLEnableTextSelection -bool YES

Disable the ‘Are you sure you want to open this application?’
dialog - defaults write com.apple.LaunchServices LSQuarantine -bool false

Show all filename extensions in Finder
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

Avoid creating .DS_Store files on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

 

Install Xcode

I choose to download Xcode from Mac App store, however you may only need the command line tools.  Since I sometimes also work on iOS projects, as well as use Quartz Composer to create files that I can load into Serato for VJing, I like to install the entire Xcode environment.

add command line tools from command line
xcode-select —install

 

INSTALL BREW & CASKROOM

I stuck with Brew as my main package manager, and adopted Caskroom to handle installing browsers and other DMG based app installs.  This lets me manage and update all my frameworks and apps from the command line, and not have to worry about being out of date, and more easily manage dependancies.  It also allows for having different versions running, in different folders, as required by different projects.  One thing I realized after the fact, is that Caskroom does not install apps into the Applications folder by default.  This is fine with me, since I use Spotlight to launch apps the majority of the time, but others might have a different preference.

http://brew.sh/
http://caskroom.io/

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

after it has finished, check install by typing.

brew doctor

it may require Xquartz being updated to 2.7.7 – go here https://xquartz.macosforge.org/landing/ – (fwiw, I had to restart after it finishes even tho it says to just log out, in order to get the new version working.)

Install Caskroom

brew install caskroom/cask/brew-cask

Download and install some essential apps

brew cask install google-chrome
brew cask install firefox
brew cask install opera
brew cask install atom
brew cask install carbon-copy-cloner
brew cask install skype

 

INSTALL GIT & Add SSH Keys

brew install git

OR for more info go to https://help.github.com/articles/set-up-git during git install, may go into wrong location. (download at http://git-scm.com/downloads)

add the following to ~/.bash_profile:

export PATH=/usr/local/git/bin:$PATH

save and then logout and back in

check version installed by typing

git version

make sure it is installed at /usr/local/bin/git/ by typing

which git

Create account on GitHub – Install Git (http://git-scm.com/downloads)

Set default username
git config --global user.name "Your Name Here"

Set default email
git config --global user.email your_email@example.com

Setup git with SSH key https://help.github.com/articles/generating-ssh-keys , might have to set permissions on .ssh folder properly (.ssh/ folder itself should be 700, id_rsa file should be 600)

git clone a project to make sure it is working

 

INSTALL RUBY

Install ruby –  

\curl -L https://get.rvm.io | bash -s stable —ruby

http://railsapps.github.io/installrubyonrails-mac.html
Start at “Install Ruby Using RVM” and follow all steps listed

I had to force ruby 2.2.2 bc rvm stable was only giving me 2.2.1

rvm install ruby-2.2.2
rvm --default use ruby-2.2.2

I used this workflow, because it allows me to install specific gemsets and versions Ruby specific to a project.   This was important because I have had to support some older Rails apps in the past, and with a normal install switching versions and gems can be a pain to manage.

mkdir myapp
cd myapp
rvm use ruby-2.2.2@myapp --ruby-version --create
gem install rails
rails new .

 

INSTALL PHP

I decided to try to get the same setup working in PHP, so that I could run different projects with different versions.

I followed this solution, which allows for on the fly switching of PHP versions.  Very handy.  The one thing to note here, is that you need to switch to each php version when running ‘brew update’ to make sure each PHP version gets updated.
http://getgrav.org/blog/mac-os-x-apache-setup-multiple-php-versions

i also followed the instructions here to add Laravel framework
http://www.createdbypete.com/articles/php-54-development-on-os-x-with-mysql-and-laravel-4/

start apache
sudo apachectl start
go to http://localhost to test

First I followed the suggestion to change my document root to a new ~/Sites folder (instead of using default /Library/WebServer/Documents folder).  I then changed my directory, user / group permissions.

Next, I used our already installed Brew package manager to install PHP, and Composer (which is yet another dependency manager, but for PHP).  I then use Composer to install Laravel.  Also noted, I install the PHP-Mcrypt module, which Laravel needs.

brew tap homebrew/dupes

brew tap homebrew/versions

brew tap homebrew/homebrew-php

brew install php54

brew install php55

brew install php56

brew install homebrew/php/composer

edit httpd.conf and add:

# Brew PHP LoadModule

LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

restart apache

sudo apachectl restart

test installation by going to http://localhost in browser

Next, we will add the ability to switch PHP versions on the fly

mkdir -p ~/bin/

$ curl -L https://raw.githubusercontent.com/conradkleinespel/sphp-osx/master/sphp >~/bin/sphp

chmod +x ~/bin/sphp

edit .bash_profile to add new bin

export PATH=/usr/local/git/bin:/usr/local/sbin:$PATH:/Users/developer/bin

edit httpd.conf again and change this line:

LoadModulephp5_module /usr/local/lib/libphp5.so

switch to php 5.4, and then restart apache

sphp 54

sudo apachectl restart

now, we should be able to switch php versions very easily

sphp 56

and now we are running php 5.6! very cool.

so, now I switch back to 5.4, and proceed with the Laravel install.

First things first, I am going to add the Mcrypt module via brew

brew install php54-mcrypt

However, the 5.4 version fails for me, which I have yet to resolve.

==> Installing php54-mcrypt from homebrew/homebrew-php
==> Installing dependencies for php54-mcrypt: mhash, mcrypt
==> Installing php54-mcrypt dependency: mhash
==> Downloading https://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource “mhash”
Download failed: https://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

so I switch to PHP 5.5 and install

brew install php55-mcrypt

i then switch to 5.6 and do the same

brew install php56-mcrypt

I can then create a new laravel project by going to my workspace folder, and using Composer to create a new Laravel project

composer create-project laravel/laravel mynewlaravelproject --prefer-dist

 

Install MYSQL

https://gist.github.com/kevinelliott/0726211d17020a6abc1f

brew install mysql

brew pin mysql

Check what version was installed. replace version number in bold in steps 4 and 9 below
ls -la /usr/local/Cellar/mysql

mkdir -p ~/Library/LaunchAgents && cp /usr/local/Cellar/mysql/5.6.24/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/

# Edit launch agent and set both keepalive and launch at startup to false – vi ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# Inject launch agent – launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# Set up databases to run as your user account – unset TMPDIR && mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

# Start mysql – mysql.server start

# Secure mysql – /usr/local/Cellar/mysql/5.6.24/bin/mysql_secure_installation

 

Install Postgres

https://gist.github.com/kevinelliott/0726211d17020a6abc1f

brew install postgres --no-ossp-uuid

brew pin postgres

initdb /usr/local/var/postgres (mine was already here)

ls -la /usr/local/Cellar/postgresql to see what version was installed. replace version number in bold in step 6 below

mkdir -p ~/Library/LaunchAgents

cp /usr/local/Cellar/postgresql/9.4.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/

# Edit launchctl script (set to not start automatically and keepalive false) – vi ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

postgres -D /usr/local/var/postgres

 

Install NPM and Node.js

http://shapeshed.com/setting-up-nodejs-and-npm-on-mac-osx/

brew install node

go into workspace folder and create a folder called nodetest

create a new file called server.js and enter code.

var http = require('http');
http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n'); }).listen(8124, "localhost");
console.log('Server running at http://localhost:8124/');

save file and run
node server.js

go to http://localhost:8124 and u should see “Hello World”

npm install express

 

Install Gulp, Grunt, Bower & Yeoman, Angular, and Ember CLI

http://juristr.com/blog/2014/08/node-grunt-yeoman-bower/

npm install -g gulp

npm install grunt

npm install -g grunt-cli

npm install -g bower

npm install -g yo

npm install -g generator-angular

npm install -g ember-cli

 

RESOURCES

https://gist.github.com/saetia/1623487

https://gist.github.com/kimmobrunfeldt/350f4898d1b82cf10bce

https://gist.github.com/kevinelliott/0726211d17020a6abc1f

http://railsapps.github.io/installrubyonrails-mac.html

http://getgrav.org/blog/mac-os-x-apache-setup-multiple-php-versions

http://openphoto.net/gallery/image/view/18493

Comments are closed.