Skip to content

Instantly share code, notes, and snippets.

@yovanoc
Last active June 14, 2019 12:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yovanoc/52cd926123e12c0384e14ce0d660ddc5 to your computer and use it in GitHub Desktop.
Save yovanoc/52cd926123e12c0384e14ce0d660ddc5 to your computer and use it in GitHub Desktop.
Development Environment for OSX.

Mac OS X Development Environment

I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

Install Software

The software selected is software that is "tried and true" --- software I need after any fresh install. I often install other software not listed here, but is handled in a case-by-case basis.

Install from App Store

Install from Third-Party Websites

  • Browsers

    • Chrome (installed via Cask)
    • Firefox (installed via Cask)
    • Opera (installed via Cask)
  • Development

    • Atom (installed via Cask)
    • I used a lot PhpStorm but if you're not a student isn't free...
  • Utilities

  • Virtualization

    • Parallels Desktop (installed via Cask)
    • Vagrant (installed via Cask)

Fonts

Open downloaded font and press "Install Font".

#Xcode Command Line Tools

Xcode > Preferences > Downloads > Command Line Tools

OR

xcode-select --install

#Homebrew

Run Xcode and accept the license

Homebrew can not install properly until this occurs.

Install Homebrew

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

At the time of this writing, brew doctor says that Xcode 6.1 is required, which means downloading it from the Apple Developer Center until it is released in the Mac App Store.

Install Homebrew extension Cask

brew tap caskroom/cask

Install common applications via Homebrew

Databases are installed later.

brew install ack autojump automake colordiff curl git git-flow \
             hub icoutils imagemagick libmemcached memcached openssl ossp-uuid qt \
             readline redis tmux wget libxml2

##Node

brew install node

Fix permissions to allow installation without sudo.

sudo chown -R `whoami` /usr/local/lib/node_modules
sudo chown -R `whoami` ~/.npm

Install grunt and bower

npm install -g grunt-cli
npm install -g bower

Install applications via Homebrew Cask

brew cask install atom
brew cask install firefox
brew cask install slack
brew cask install dropbox
brew cask install discord
brew cask install github-desktop
brew cask install parallels-desktop
brew cask install google-chrome-canary
brew cask install iterm2
brew cask install vagrant
brew cask install vagrant-manager

Install Parallels plugin for Vagrant

vagrant plugin install vagrant-parallels

See http://parallels.github.io/vagrant-parallels/ for more details.

#Shell

iTerm - Solarized Solarized

Get the iTerm color settings

Just save it somewhere and open the file(s). The color settings will be imported into iTerm2. Apply them in iTerm through iTerm -> preferences -> profiles -> colors -> load presets. You can create a different profile, other than Default if you wish to do so.

Oh my zsh

More info here: https://github.com/robbyrussell/oh-my-zsh

Install with curl

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

When the installation is done, edit ~/.zshrc and set ZSH_THEME="agnoster"

Install a patched font

Set Meslo font in iTerm2 (14px is my personal preference) (iTerm -> preferences -> profiles -> text).

  • Regular Font -> "Change Font"
  • Non-ASCII Font -> "Change Font"

Restart iTerm2 for all changes to take effect.

Further tweaking

Things like

  • auto suggestions
  • word jumping with arrow keys
  • shorter prompt style
  • syntax highlighting

can be found in the section below.

Auto suggestions (for oh-my-zsh)

Auto suggestions

Just follow these steps: https://github.com/tarruda/zsh-autosuggestions#oh-my-zsh

Enable word jumps

By default, word jumps (option + → or ←) do not work. You can make this work by adding the following to your ~/.zshrc

bindkey -e
bindkey '^[[1;9C' forward-word
bindkey '^[[1;9D' backward-word

If that does not work, an alternative is to go to iTerm - preferences - Keys.

Under global shortcut keys, add the following keyboard shortcuts:

Option + right

⌥→
Send Escape Sequence
f

Option + left

⌥←
Send Escape Sequence
b

Shorter prompt style

By default, your prompt will now show “user@hostname” in the prompt. This will make your prompt rather bloated. Optionally set DEFAULT_USER in ~/.zshrc to your regular username (these must match) to hide the “user@hostname” info when you’re logged in as yourself on your local machine. You can check your username value by executing whoami in the terminal.

Syntax highlighting

brew install zsh-syntax-highlighting

If you do not have or do not like homebrew, follow the the installation instructions instead.

After installation through homebrew, add

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

to the end of your .zshrc file. After that, it's best to restart your terminal. Sourcing your ~/.zshrc does not seem to work well with this plugin.

OS X Preferences

#Set a blazingly fast keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 0.02

#Set a shorter Delay until key repeat
defaults write NSGlobalDomain InitialKeyRepeat -int 12

#Add a context menu item for showing the Web Inspector in web views
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true

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

#Store screenshots in subfolder on desktop
mkdir ~/Desktop/Screenshots
defaults write com.apple.screencapture location ~/Desktop/Screenshots

Set hostname

sudo scutil --set HostName SpaceX-Falcon-9

#Git

Setup Github

ssh-keygen -t rsa -C "yovano_c@outlook.com"

ssh-add ~/.ssh/id_rsa

# Copy ssh key to github.com
pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

# Test connection
ssh -T git@github.com

# Set git config values
git config --global user.name "Christopher Yovanovitch"
git config --global user.email "yovano_c@outlook.com"

git config --global color.ui true

#Configure Apache/Mysql/PHP

##PHP

brew upgrade && \
brew tap homebrew/dupes && \
brew tap homebrew/versions && \
brew tap homebrew/homebrew-php && \
brew install freetype jpeg libpng gd zlib && \
brew install --with-fpm --with-mysql php56
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents

##Install dnsmasq

brew install dnsmasq

cd $(brew --prefix)

mkdir etc

echo 'address=/.dev/127.0.0.1' > etc/dnsmasq.conf

sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons

Enter your admin password. Then paste the rest:

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

sudo mkdir /etc/resolver

sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'

##httpd.conf

Edit /private/etc/apache2/httpd.conf

atom /private/etc/apache2/httpd.conf

… and uncomment these lines by removing the # (not remove the line 169 and put the line 170 to your php version installed with homebrew):

# line 160
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
# line 168
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
# line 169
LoadModule php5_module libexec/apache2/libphp5.so
# line 170
LoadModule php5_module /usr/local/Cellar/php56/5.6.23/libexec/apache2/libphp5.so
# line 499
Include /private/etc/apache2/extra/httpd-vhosts.conf

Add “index.php” in line 271:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Change User & Group on lines 181/182 based on YOURUSERNAME (name of your homefolder (whoami in terminal))

User YOURUSERNAME
Group staff

##php.ini

Create and edit /private/etc/php.ini:

sudo cp /private/etc/php.ini.default /private/etc/php.ini

subl /private/etc/php.ini

… now remove the semicolon (;) in front of line 791 (Yosemite) / line 788 (El Capitan) and edit the line to look like this:

upload_tmp_dir = /tmp

… and remove the semicolon (;) from line 1390 (Yosemite) / line 1366 or 1387 (El Capitan):

session.save_path = "/tmp"

##www folder

  • Create a folder in your home directory called www.
mkdir ~/www

Or if you prefer, like me, sync all your projects (www folder in iCloud) :

  • Create the www folder in iCloud.
mkdir ~/Library/Mobile Documents/com~apple~CloudDocs/www

AND don't forget to symlink!

ln -s ~/Library/Mobile\ Documents/com~apple~CloudDocs/www ~/

This is the folder where all your projects will live in subdirectories. If you would like to put it in a different location, make sure you also use the changed path in the next step below. Inside the newly created folder, make another folder called _localhost:

mkdir ~/www/_localhost

This is where you can put a default page that is shown when you navigate to 127.0.0.1 or to localhost in your browser, or if someone on your local networks enters your machine’s IP address in their browser.

##httpd-vhosts.conf

Edit /private/etc/apache2/extra/httpd-vhosts.conf:

atom /private/etc/apache2/extra/httpd-vhosts.conf

Delete everything after line 22 and paste this (replace YOURUSERNAME with your home directory’s name):

<Directory "/Users/YOURUSERNAME/www">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
<Virtualhost *:80>
    VirtualDocumentRoot "/Users/YOURUSERNAME/www/_localhost"
    UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
   VirtualDocumentRoot "/Users/YOURUSERNAME/www/%2"
   ServerName sites.dev
   ServerAlias www.*.dev
   ServerAlias www.*.dev.*.xip.io
   UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
    VirtualDocumentRoot "/Users/YOURUSERNAME/www/%1"
    ServerName sites.dev
    ServerAlias *.dev
    ServerAlias *.dev.*.xip.io
    UseCanonicalName Off
</Virtualhost>

##Install MYSQL

Paste this into your Terminal to install and configure MySQL:

brew install mysql
mysql.server restart
mysql_secure_installation

Follow the instructions on your screen. Don’t worry, it’s only a few steps and will make your MySQL installation much more secure.

Paste this into your Terminal to create a new database:

mysql.server stop

mysqld -initialize --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

OS X expects the MySQL socket to sit in /var/mysql, so we create that folder and add a symbolic link to where the socket actually lives:

sudo mkdir /var/mysql
sudo chmod 755 /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Now try starting the MySQL server:

mysql.server start

You should now be able to use Sequel Pro to access your databases. Just enter the MySQL user name (the default is root) and the password (that you’ve created a minute ago) in the Socket tab and you should be connected.

##Composer

Install Composer (It's used in many project) :

brew install composer

export PATH="$PATH:$HOME/.composer/vendor/bin" # Add composer bin directory to PATH

##Done!

You can now start Apache and MySQL like this:

mysql.server start
sudo apachectl restart

And quit them like this:

mysql.server stop
sudo apachectl stop

If everything has worked out, every folder you create in ~/www like, say:

~/www/myawesomesite

… will automatically be accessible as a .dev domain on your local machine as both:

myawesomesite.dev

… and:

www.myawesomesite.dev

And because you always want to test your sites on dozens of mobile devices and legacy windows machines, you can now also access it from other devices on your local network:

myawesomesite.dev.X.X.X.X.xip.io

…where X.X.X.X is, of course, your computer’s IP address.

If your router’s DNS blocks the xip.io service, you can set up Google’s DNS (8.8.8.8) on your devices so they can find your Mac’s server. REMEMBER: All of your sites are now easily accessible on the local network through xip.io mapping. So maybe you don’t want to run this when you’re in an untrusted local network (which you should never be in anyway).

You could also add HTTP authentication or other measures that you would use on a live site for access protection. If you have any suggestions on how to make this tutorial better/easier/more secure, please comment!

aww yeah

@antonioreyna
Copy link

Great tutorial!!

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment