OSX Fresh Install Semi Automatic Setup
Getting upto speed effortlessly.
Xcode command line tools
We need the xcode command line tools to compile stuff. So
$ xcode-select --install
Accept the dialog box to install the tools. You may download XCode from the App Store if needed.
oh-my-zsh
Zsh has some nifty features over bash, particularly the recursive globbing.
$ curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
Homebrew
It’s nice to have a package manager do the work.
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Now that homebrew is up and running, let’s get some tools and apps. The below linked gist can be downloaded as a shell script and executed. While you’re at it, you can add your own tools and apps to the list.
Git setup
$ ssh-keygen -t rsa -C "varun@yellina.io"
copy ssh key to github.com
$ ssh-add ~/.ssh/id_rsa
copy ssh key to clipboard, add it to your ssh keys on github and bitbucket.
$ pbcopy < ~/.ssh/id_rsa.pub
test connection
$ ssh -T git@github.com
set git config values
$ git config --global user.name "Varun Yellina"
$ git config --global user.email "varun@yellina.io"
$ git config --global github.user varunyellina
$ git config --global github.token your_token_here
$ git config --global core.editor "subl -w"
$ git config --global color.ui true
Node
Node and npm can be installed with homebrew. Node now comes with npm.
$ 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
Nginx
Install nginx
$ brew install nginx
Next change nginx port to default http port 80
$ nano /usr/local/etc/nginx/nginx.conf
from
server {
listen 8080;
to
server {
listen 80;
Now let’s get it running
$ sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
$ sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
DNSMasq
$ brew install dnsmasq
$ mkdir -p /usr/local/etc/
$ echo "address=/dev/127.0.0.1" >> /usr/local/etc/dnsmasq.conf
$ echo "listen-address=127.0.0.1" >> /usr/local/etc/dnsmasq.conf
$ sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
$ sudo launchctl load -w "/Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist"
$ sudo -s
$ sudo mkdir -p /etc/resolver
$ sudo echo 'nameserver 127.0.0.1' > /etc/resolver/dev
$ dscacheutil -flushcache
Dynamic virtual hosts
Now that we have installed dnsmasq
to resolve domains ending with .dev
to point to 127.0.0.1
, let’s configure nginx to dynamically configure virtual hosts.
I configured my nginx to use /Users/varun/Sites
folder as webroot.
Now let us say I have my websites in this order
~/Sites
~/Sites/portfolio
~/Sites/survey
~/Sites/portal
We have to create a separate folder for all our sites.
$ mkdir -p /usr/local/etc/nginx/sites-available/
$ mkdir -p /usr/local/etc/nginx/sites-enabled/
Since that is done, we have to tell nginx about the locations. Edit the nginx.conf and include the follwing line in the http {} section
include /usr/local/etc/nginx/sites-enabled/*;
Now, let’s put in a default config. I’ve a gist which we’ll make some changes to.
$ curl -L https://gist.githubusercontent.com/varunyellina/43bd692cd9eb66076332/raw/default | sed -e "s/varunyellina/$USER/" > /usr/local/etc/nginx/sites-available/default
Next, we’ll put in a config that’ll resolve all .dev domains to the respective folders in /Users/yourusername/Sites folder.
$ curl -L https://gist.githubusercontent.com/varunyellina/44440f889479cb8d8628/raw/localsite | sed -e "s/varunyellina/$USER/" > /usr/local/etc/nginx/sites-available/localsite
We now enable the config by using a symlink.
$ ln -s /usr/local/etc/nginx/sites-available/localsite /usr/local/etc/nginx/sites-enabled/localsite
Now just restart your nginx service, and you are good to go.
$ sudo nginx -s stop
$ sudo nginx
Accessing your local website is automatic now.
~/Sites | -- | localhost |
~/Sites/portfolio | -- | portfolio.dev |
~/Sites/survey | -- | survey.dev |
~/Sites/portal | -- | portal.dev |
MariaDB
brew install mariadb Install databases
$ unset TMPDIR
$ mysql_install_db --user=`whoami` --basedir="$(brew --prefix mariadb)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Now start mysql server
$ mysql.server start
Change root password and remove test databases. The default password is either root or there is no password, just hit return.
$ /usr/local/opt/mariadb/bin/mysql_secure_installation
Start mariadb on boot
$ ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
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
$ mkdir -p /usr/local/etc/nginx/conf.d/
Add php-fpm configuration to the file at /usr/local/etc/nginx/conf.d/php-fpm
1
2
3
4
5
6
7
8
9
10
11
12
location ~ \.php$ {
try_files $uri $uri/ /index.php?$args ;
index index.html index.htm index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include fastcgi_params;
}
Load php-fpm
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist