Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install NGINX, PHP-FPM (5.5.6), Mongo and MySql
#############################################################################
# current prompt
#############################################################################
# \d – Current date
# \t – Current time
# \h – Host name
# \# – Command number
# \u – User name
# \W – Current working directory (ie: Desktop/)
# \w – Current working directory, full path (ie: /Users/Admin/Desktop)
# export PS1="\u@\h\w: "
export PS1="\w: "
#############################################################################
# git autocomplet and bash prompt
#############################################################################
source `brew --prefix git`/etc/bash_completion.d/git-completion.bash
source `brew --prefix git`/etc/bash_completion.d/git-prompt.sh
# configure git and prompt
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="git verbose legacy"
export PSORIG="$PS1" # pokud chcete zachovat puvodni PS1
PS1=$PSORIG'$(__git_ps1 "\[\033[01;31m\]%s \[\033[00m\]")'
# If you get error like: `Dubious ownership on file...` need to change rights:
# sudo chown root <file>
# sudo chmod 644 <filename>
#############################################################################
# nginx aliases
#############################################################################
alias nginx-start="sudo nginx"
alias nginx-restart="sudo nginx -s reload"
alias nginx-stop="sudo nginx -s stop"
#############################################################################
# php-fpm aliases
#############################################################################
alias php-start="sudo launchctl load ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist"
alias php-stop="sudo launchctl unload ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist"
alias php-restart="php-stop && php-start"
#############################################################################
# mongo aliases
#############################################################################
alias mongo-start="sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist"
alias mongo-stop="sudo launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist"
alias mongo-restart="mongo-stop && mongo-start"
#############################################################################
# mysql
#############################################################################
alias mysql-start="sudo mysql.server start"
alias mysql-stop="sudo mysql.server stop"
alias mysql-restart="mysql-stop && mysql-start"
#############################################################################
# memcached
#############################################################################
alias memcached-start="sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached-stop="sudo launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached-restart="memcached-stop && memcached-start"
#############################################################################
# aliases
#############################################################################
alias drives="df -h" # list all drives
alias listen="sudo lsof -i -P | grep -i \"listen\"" # listen on ports
alias preview="open -a '$PREVIEW'"
alias xcode="open -a '/Developer/Applications/Xcode.app'"
alias safari="open -a safari"
alias firefox="open -a firefox"
alias opera="open -a opera"
alias chrome="open -a google\ chrome"
alias f='open -a Finder'
alias please=sudo
#############################################################################
# List aliases
#############################################################################
# List all files colorized in long format
alias l="ls -l --color"
# List all files colorized in long format, including dot files
alias la="ls -la --color"
# List all alias
alias ll="ls -la" # ll alias
# List only directories
alias lsd='ls -l | grep "^d"'
# list alias with -G
alias ls="command ls -G"
#############################################################################
# Others
#############################################################################
# Enhanced WHOIS lookups
alias whois="whois -h whois-servers.net"
# Flush Directory Service cache
alias flush="dscacheutil -flushcache"
# File size
alias fs="stat -f \"%z bytes\""
#############################################################################
# Prefer US English and use UTF-8
#############################################################################
export LC_ALL="en_US.UTF-8"
export LANG="en_US"
#############################################################################
# path
#############################################################################
export PATH="/usr/local/Cellar/coreutils/8.21/libexec/gnubin:/usr/local/bin:/usr/local/sbin:$PATH"
#############################################################################
# bash history size
#############################################################################
export HISTCONTROL=erasedups
export HISTSIZE=10000
shopt -s histappend

Install NGINX, PHP-FPM (5.5.6), Mongo and MySql

Preparation

Download Sublime editor and create link subl:

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

Install Homebrew

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

NGINX

Install

brew install nginx

Running

Follow command will autostart nginx after login

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

You can start nginx manually and check if running in browser

sudo nginx            # start
sudo nginx -s stop    # stop
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

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

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    include       sites-enabled/*.dev; # load virtuals config
    sendfile        on;

    keepalive_timeout  65;

    # gzip  on;
    # gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    server {
        listen       80;
        server_name  localhost;

        location / {
            root  /Users/roman/Sites;
            try_files  $uri  $uri/  /index.php?$args ;
            index  index.php;
        }

        # configure *.PHP requests
        
        location ~ \.php$ {
            root  /Users/roman/Sites;
            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;
        }
    }
}

Setup virtuals

First prepare follow dirs

mkdir /usr/local/etc/nginx/sites-available
mkdir /usr/local/etc/nginx/sites-enabled

Create first dev configuration:

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

Here is my example configuration:

server {
  listen                *:80;
  server_name           omdesign.dev;
  #access_log           /Users/roman/Work/omdesign.cz/log/omdesign.dev.access.log;
  #error_log            /Users/roman/Work/omdesign.cz/log/omdesign.dev.error.log;

  location / {
    root  /Users/roman/Work/omdesign.cz;
    try_files  $uri  $uri/  /index.php?$args;
    index index.php;
  }

  location ~ \.php$ {
    root  /Users/roman/Work/omdesign.cz;
    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;
  }

}

Create symlink to sites-enabled:

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:

127.0.0.1	omdesign.dev

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

PHP-fpm

Install

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install --without-apache --with-fpm --with-mysql php55

Launch after login

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

Install PHP extensions

brew install php55-mongo
brew install php55-xdebug
brew install php55-memcache
brew install php55-memcached
brew install php55-opcache

add launch agent for memcached

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

or get others

brew search php55

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

brew install php55-apcu # APC

Replace OS X PHP

change ~/.bash_profile add follow line:

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:

subl /usr/local/etc/php/5.5/conf.d/zzzzzzzzzzzz.ini

See my configuration:

short_open_tag = On
display_errors = On
display_startup_errors = On
upload_max_filesize = 256M
date.timezone = "Europe/Prague"
error_reporting = E_ALL

xdebug.idekey=PHPSTORM

mongo

brew install mongodb
brew link mongod

Setup to autostart after login

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

Start & restart

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

mysql

brew install mysql

Setup to autostart after login

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

Change rights

sudo chown -R _mysql /usr/local/var/mysql

Start & restart

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Confugure

First setup new password for root

mysqladmin -u root password

bash (need to be upgrade for new Git)

brew install bash

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

sudo subl /etc/shells

add this line at the end of the list:

/usr/local/bin/bash

and

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

after that relaunch Terminal and check bash version

echo $BASH_VERSION

git

brew install git
brew unlink git && brew link git
brew info git

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

#############################################################################
# My current prompt
#############################################################################

export PS1="\w: " 

#############################################################################
# git autocomplet and bash prompt
#############################################################################

source `brew --prefix git`/etc/bash_completion.d/git-completion.bash
source `brew --prefix git`/etc/bash_completion.d/git-prompt.sh

# configure yout git and prompt

GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="git verbose legacy"

export PSORIG="$PS1" # or remove if you don't have My custom prompt

PS1=$PSORIG'$(__git_ps1 "\[\033[01;31m\]%s \[\033[00m\]")'

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

Others

brew install npm

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

brew install coreutils

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

Find, Locate etc. for mac

brew install findutils

Rename command:

brew install rename

Tree command for mac:

brew install tree

Install wget:

brew install wget --enable-iri

See .brew for more information

sudo port -fp uninstall installed
sudo rm -rf \
/opt/local \
/Applications/DarwinPorts \
/Applications/MacPorts \
/Library/LaunchDaemons/org.macports.* \
/Library/Receipts/DarwinPorts*.pkg \
/Library/Receipts/MacPorts*.pkg \
/Library/StartupItems/DarwinPortsStartup \
/Library/Tcl/darwinports1.0 \
/Library/Tcl/macports1.0 \
~/.macports
@daruwanov

This comment has been minimized.

Copy link

commented Dec 9, 2014

Hi. Can you help me.
I try to use your instruction. All works fine. I have only one issue with mysql.

after running mysqladmin -u root password

i have errors

error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

Can you help my with this? Please.

@evansantos

This comment has been minimized.

Copy link

commented May 18, 2015

@daruwanov I stucked at this step, but then i resolved this issue following this post > http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.