Skip to content

Instantly share code, notes, and snippets.

@hackzilla
Forked from ogrrd/Mac Dev Setup.md
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackzilla/d2daec83a3772ac92096 to your computer and use it in GitHub Desktop.
Save hackzilla/d2daec83a3772ac92096 to your computer and use it in GitHub Desktop.

Fix some things in php.ini

$ pico /etc/php5/fpm/php.ini

Fix the timezone

Locate and update the date.timezone variable as per best practice

date.timezone = "UTC";

Installing a Web Developer setup on OS X Mavericks

Install XQuartz

A version of the X.Org X Window System that runs on OS X

Download and install xquartz.macosforge.org

Install Brew

Homebrew or Brew is a package manager for OS X and will allow us to install PHP, MySQL and nginx.

  1. Open a Terminal window

  2. Install brew

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"


1. Make sure your system is ready to brew!

  ```bash
$ brew doctor
  1. Now update brew so we're installing the latest packages
$ brew update
  1. Install wget
$ brew install wget
  1. Edit your bash profile
$ nano ~/.bash_profile
  1. Put the following lines at the bottom (don't worry if this file is empty!)

PATH=/usr/local/sbin:/usr/local/bin:$PATH; source brew --prefix/Library/Contributions/brew_bash_completion.sh


1. Save and exit with `CTRL` + `O`, `Return` and then `CTRL` + `X`
1. Reload bash profile without relogging

	```bash
$ source ~/.bash_profile

Install Git

Only do this if you'd like to use Git as part of your development process.

  1. Install

$ brew install git


1. Configure

	```bash
$ git config --global user.name "your name here"
$ git config --global user.email "your email here"
  1. I don't like vi so let's use nano instead

$ git config --global core.editor "nano"


1. Let's get some colour coding in our Git shell! *(optional)*

	```bash
$ git config --global color.ui true
  1. Let's get Git info in our shell! Follow the instructions here (optional)

Install (E)nginx, MySQL, PHP

Visit the amazing brew-emp Homebrew (E)nginx MySQL PHP Installer and follow the instructions!

Secure your setup (optional)

MySQL ships with no root password and an anonymous account and lets anyone connect from your LAN. If you're at a conference or just in the office, that means anyone can access your databases with root!

$ mysql_secure_installation

...and follow the prompts.

Install Composer

The Dependency Manager for PHP

$ curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir=/usr/local/bin

Renaming then linking in this way allows us to perform composer selfupdate without ill effects.

Create nginx conf for regular PHP sites

Create/Modify /etc/nginx/conf.d/php-fpm.conf

upstream php {
    #this should match value of "listen" directive in php-fpm pool
	server unix:/var/run/php5-fpm.sock;
#	server 127.0.0.1:9000;
}
mkdir /etc/nginx/common

Create/Modify /etc/nginx/common/common

include /etc/nginx/common/hidden;

location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

Create/Modify /etc/nginx/common/hidden

location ~ /\. {
    deny all;
}

Create/Modify /etc/nginx/common/php

include /etc/nginx/common/common;

location ~ \.php$ {
    fastcgi_pass   php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffer_size 4k;
    fastcgi_buffers 256 4k;
    fastcgi_max_temp_file_size 0;
    include        fastcgi_params;
}

Make core config for Symfony2 sites

Create/Modify /usr/local/etc/nginx/common/symfony2

include /etc/nginx/common/common;

location /app_dev.php {
    try_files $uri /app_dev.php/$args;
}

location / {
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

location ~ ^/(app|app_dev|config)\.php(/|$) {
    fastcgi_pass   php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    fastcgi_buffer_size 4k;
    fastcgi_buffers 256 4k;
    fastcgi_max_temp_file_size 0;
}

Make core config for Kohana2 sites

Create/Modify /usr/local/etc/nginx/common/kohana

include /etc/nginx/common/common;

# ROUTING TO KOHANA IF REQUIRED
location / {
	try_files $uri $uri/ @kohana;
}

# FOR PHP FILES
location ~* \.php$ {
	# PHP FILES MIGHT BE TO HANDLED BY KOHANA
	try_files $uri $uri/ @kohana;

	fastcgi_pass   php;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
}


# HANDLES THE REWRITTEN URLS TO KOHANA CONTROLLER
location @kohana
{
	fastcgi_pass   php;
	fastcgi_index index.php;
	include fastcgi_params;
	fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}

Make core config for wordpress sites

Create/Modify /usr/local/etc/nginx/common/wordpress for wordpress sites

include /etc/nginx/common/common;

# WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
    try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
	# Zero-day exploit defense.
	# http://forum.nginx.org/read.php?2,88845,page=3
	# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
	# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine.  And then cross your fingers that you won't get hacked.
	try_files $uri =404;

	fastcgi_split_path_info ^(.+\.php)(/.+)$;
	#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

	include fastcgi_params;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#	fastcgi_intercept_errors on;
	fastcgi_pass php;
}

You can make an equivalent files for sites, call them *_dev

Create skeleton for local dev sites

Create /etc/nginx/sites-available/mysite.dev

server {
    listen       80;
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
    server_name  mysite.dev;
    root /Users/og/Sites/mysite.dev;

    index index.php index.html index.htm;

    access_log /usr/local/var/log/nginx/mysite.access.log;
    error_log  /usr/local/var/log/nginx/mysite.error.log;

    include /etc/nginx/common/php; # or /etc/nginx/common/symfony2 or /etc/nginx/common/wordpress
}

Copy this file to myproject.dev (or whatever) and change every instance of "mysite" with "mygreatproject"

Enable new site

$ cd /etc/nginx/sites-enabled
$ ln -s ../sites-available/mygreatproject.dev

Restart all the things!

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