Hot to install nginx, PHP-fpm 5.5.6, mongo and MySql on mac with homebrew

ALERT!!! Latest version of follow procedure can be found here https://github.com/OzzyCzech/dotfiles/blob/master/readme.md

Preparation

Download Sublime editor and create link subl:

  1. sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /bin/subl

Install Homebrew

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

NGINX

Install

  1. brew install nginx

Running

Follow command will autostart nginx after login

  1. ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents

You can start nginx manually and check if running in browser

  1. sudo nginx            # start
  2. sudo nginx -s stop    # stop
  3. sudo nginx -s reload  # restart

Check if running open http://localhost:8080 or open http://localhost:80

Configuration

nginx configuration files can be found here subl /usr/local/etc/nginx/nginx

Here is my basic nginx.conf file (do not forgot change root path):

  1. #user  nobody;
  2. worker_processes  1;
  3.   4.  [#error_log](http://www.nabito.net/tag/error_log)  logs/error.log;
  5.  [#error_log](http://www.nabito.net/tag/error_log)  logs/error.log  notice;
  6.  [#error_log](http://www.nabito.net/tag/error_log)  logs/error.log  info;
  7.   8. events {
  9.     worker_connections  1024;
  10. }
  11.   12. http {
  13.     include       mime.types;
  14.     include       sites-enabled/*.dev; # load virtuals config
  15.     sendfile        on;
  16.   17.     keepalive_timeout  65;
  18.   19.     # gzip  on;
  20.     # gzip_disable "MSIE [1-6]\.(?!.*SV1)";
  21.   22.     server {
  23.         listen       80;
  24.         server_name  localhost;
  25.   26.         location / {
  27.             root  /Users/roman/Sites;
  28.             try_files  $uri  $uri/  /index.php?$args ;
  29.             index  index.php;
  30.         }
  31.   32.         # configure *.PHP requests
  33.   34.         location ~ \.php$ {
  35.             root  /Users/roman/Sites;
  36.             try_files  $uri  $uri/  /index.php?$args ;
  37.             index  index.html index.htm index.php;
  38.             fastcgi_param PATH_INFO $fastcgi_path_info;
  39.             fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  40.             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  41.   42.             fastcgi_pass 127.0.0.1:9000;
  43.             fastcgi_index index.php;
  44.             fastcgi_split_path_info ^(.+\.php)(/.+)$;
  45.             fastcgi_intercept_errors on;
  46.             include fastcgi_params;
  47.         }
  48.     }
  49. }

Setup virtuals

First prepare follow dirs

  1. mkdir /usr/local/etc/nginx/sites-available
  2. mkdir /usr/local/etc/nginx/sites-enabled

Create first dev configuration:

  1. subl /usr/local/etc/nginx/sites-available/omdesign.dev

Here is my example configuration:

  1. server {
  2.   listen                *:80;
  3.   server_name           omdesign.dev;
  4.   [#access_log](http://www.nabito.net/tag/access_log)           /Users/roman/Work/omdesign.cz/log/omdesign.dev.access.log;
  5.   [#error_log](http://www.nabito.net/tag/error_log)            /Users/roman/Work/omdesign.cz/log/omdesign.dev.error.log;
  6.   7.   location / {
  8.     root  /Users/roman/Work/omdesign.cz;
  9.     try_files  $uri  $uri/  /index.php?$args;
  10.     index index.php;
  11.   }
  12.   13.   location ~ \.php$ {
  14.     root  /Users/roman/Work/omdesign.cz;
  15.     try_files  $uri  $uri/  /index.php?$args;
  16.     index  index.html index.htm index.php;
  17.   18.     fastcgi_param PATH_INFO $fastcgi_path_info;
  19.     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  20.     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  21.   22.     fastcgi_pass 127.0.0.1:9000;
  23.     fastcgi_index index.php;
  24.     fastcgi_split_path_info ^(.+\.php)(/.+)$;
  25.     fastcgi_intercept_errors on;
  26.     include fastcgi_params;
  27.   }
  28.   29. }

Create symlink to sites-enabled:

  1. sudo ln -s /usr/local/etc/nginx/sites-available/omdesign.dev /usr/local/etc/nginx/sites-nabled/omdesign.dev

Update your subl /etc/hosts file with follow line:

  1. 127.0.0.1   omdesign.dev

Restart nginx (sudo nginx -s reload) and check if working (open http://omdesign.dev)

PHP-fpm

Install

  1. brew tap homebrew/dupes
  2. brew tap josegonzalez/homebrew-php
  3. brew install --without-apache --with-fpm --with-mysql php55

Launch after login

  1. ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents

Install PHP extensions

  1. brew install php55-mongo
  2. brew install php55-xdebug
  3. brew install php55-memcache
  4. brew install php55-memcached

add launch agent for memcached

  1. ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents

or get others

  1. brew search php55

What about APC? See stackoverflow – APC have some problems but you can install emulated APC

  1. brew install php55-apcu # APC

Replace OS X PHP

change ~/.bash_profile add follow line:

  1. export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

Restart Terminal and check if working php -v or php-fpm -v

Configuration and php.ini

You can found basic php-fpm config file here subl /usr/local/etc/php/5.5/php-fpm.conf. Check especially listen = 127.0.0.1:9000 everything else can be leave as is.

PHP config files can be found here subl /usr/local/etc/php/5.5/conf.d/. You can change php.ini but its more more easly keept change is spearate file:

  1. subl /usr/local/etc/php/5.5/conf.d/99999-roman.ini

See my configuration:

  1. short_open_tag = On
  2. display_errors = On
  3. display_startup_errors = On
  4. upload_max_filesize = 256M
  5. date.timezone = "Europe/Prague"
  6. error_reporting = E_ALL
  7.   8. xdebug.idekey=PHPSTORM

mongo

  1. brew install mongodb
  2. brew link mongod

Setup to autostart after login

  1. ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

Start & restart

  1. launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
  2. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

mysql

  1. brew install mysql

Setup to autostart after login

  1. ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Confugure

First setup new password for root

  1. mysqladmin -u root password

bash (need to be upgrade for new Git)

  1. brew install bash

Open terminal cmd+, setup path to new bash /usr/local/bin/bash

  1. sudo subl /etc/shells

add this line at the end of the list:

  1. /usr/local/bin/bash

and

  1. chsh -s /usr/local/bin/bash YOUR_USER_NAME

after that relaunch Terminal and check bash version

  1. echo $BASH_VERSION

git

  1. brew install git
  2. brew unlink git && brew link git
  3. brew info git

And update your ~/.bash_profile to add autocomplete and prompt

  1. #############################################################################
  2. # My current prompt
  3. #############################################################################
  4.   5. export PS1="\w: " 
  6.   7. #############################################################################
  8. # git autocomplet and bash prompt
  9. #############################################################################
  10.   11. source `brew --prefix git`/etc/bash_completion.d/git-completion.bash
  12. source `brew --prefix git`/etc/bash_completion.d/git-prompt.sh
  13.   14. # configure yout git and prompt
  15.   16. GIT_PS1_SHOWDIRTYSTATE=1
  17. GIT_PS1_SHOWUNTRACKEDFILES=1
  18. GIT_PS1_SHOWUPSTREAM="git verbose legacy"
  19.   20. export PSORIG="$PS1" # or remove if you don't have My custom prompt
  21.   22. PS1=$PSORIG'$(__git_ps1 "\[\033[01;31m\]%s \[\033[00m\]")'

Restart terminal (need to be quit and relaunch cmd+q)

Others

  1. brew install npm

Install GNU core utilities (those that come with OS X are outdated)

  1. brew install coreutils

Don’t forget add /usr/local/Cellar/coreutils/8.21/libexec/gnubin to $PATH

Find, Locate etc. for mac

  1. brew install findutils

Rename command:

  1. brew install rename

Tree command for mac:

  1. brew install tree

Install wget:

  1. brew install wget --enable-iri

See .brew for more

See my original gist here: https://gist.github.com/OzzyCzech/7658282