Install nginx, php-fpm and MySQL on Mac OS X Mountain Lion

Before you start to install anyone of stack components, you need install macports. To install macports, please go to

Once you have installed macports, you can start to install the stack.

Remember install xcode command line tools. Open Xcode and got to Preference, select Download and install command line tools.

To install MySQL, download mysql-5.5.28-ox10.6-x86.dmg and install:


To disable automatic startup configure file /etc/hostconfig


Install Php-fpm

sudo port install php54-fpm
sudo cp /opt/local/etc/php54/php-fpm.conf.default /opt/local/etc/php54/php-fpm.conf
sudo port install php54-mysql php54-mbstring php54-APC
sudo port install php54-mcrypt
sudo port install php54-gd
sudo port install php54-curl
sudo port install php54-iconv

Install Nginx

sudo port install nginx
sudo cp -p /opt/local/etc/nginx/fastcgi.conf.example /opt/local/etc/nginx/fastcgi.conf
sudo cp /opt/local/etc/nginx/fastcgi_params.example /opt/local/etc/nginx/fastcgi_params
sudo cp /opt/local/etc/nginx/mime.types.example /opt/local/etc/nginx/mime.types
sudo cp /opt/local/etc/nginx/nginx.conf.example /opt/local/etc/nginx/nginx.conf
sudo mkdir /opt/local/etc/nginx/conf.d

Configure www pool in php-fpm.conf

pm = dynamic
pm.max_children = 1
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 500


#user nobody;
worker_processes 1;

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

#pid logs/;

events {
worker_connections 1024;

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root share/nginx/html;
index index.html index.htm;

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root share/nginx/html;

# load config files from /opt/local/etc/nginx/conf.d
include /opt/local/etc/nginx/conf.d/*.conf;

Configure start and stop command in your .bash_profile

# nginx
alias nginx_start='sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist'
alias nginx_stop='sudo launchctl unload -w /Library/LaunchDaemons/org.macports.nginx.plist'
alias nginx_restart='nginx_stop; nginx_start;'

# php-fpm
alias fpm_start=’sudo launchctl load -w /Library/LaunchDaemons/org.macports.php54-fpm.plist’
alias fpm_stop=’sudo launchctl unload -w /Library/LaunchDaemons/org.macports.php54-fpm.plist’
alias fpm_restart=’fpm_stop; fpm_start’

# mysql
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
alias sql_start=”sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart”
alias sql_stop=”sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop”
alias sql_restart=”sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart”

To stop mysql, you need kill the process.


Be Sociable, Share!

01. October 2012 by davidmataro
Categories: Uncategorized | Tags: , , , , | 1 comment

One Comment

  1. If you need SSL, you need install nginx with next command:

    sudo port install nginx +ssl

Leave a Reply

Required fields are marked *

− three = 5