Skip to content

Instantly share code, notes, and snippets.



Last active Aug 17, 2019
What would you like to do?
MacPorts Yosemite PHP+nginx Installation
# partial config from nginx.conf
server {
listen 80 default_server;
include security.conf; # ignore this
root /web/www;
index index.php index.html index.htm;
server_name _ "";
location ~ .php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_index index.php;
fastcgi_param PHP_VALUE open_basedir="/web/www";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

Note that the installiation of nginx+php5 on MACOSX IS NOT RECOMMENDED unless you know what you're trying to do.

  • both services are going to be running as root
  • there is no configuration file set for php-cgi53

Tested on OSX 10.10.2 (Yosemite)

Refer to for lower versions of MACOSX.

# install MacPorts at
user$ sudo su
root$ port selfupdate
root$ port update outdated
root$ port install nginx
root$ port install php53 +fastcgi fcgi # insert php53-(extension name) if required
root$ mkdir /opt/local/etc/LaunchDaemons/org.macports.php-fastcgi
root$ nano org.macports.php-fastcgi.plist # or vim
root$ ln -s /opt/local/bin/php53 php
root$ ln -s /opt/local/bin/php-cgi53 php
root$ cd /Libarary/LaunchDaemons
root$ ln -s /opt/local/etc/LaunchDaemons/org.macports.php-fastcgi/org.macports.php-fastcgi.plist org.macports.php-fastcgi.plist
root$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.php-fastcgi.plist

you can set further settings at /opt/local/etc/*

worker_processes 1;
pid /opt/local/var/run/nginx/;
events {
worker_connections 2048;
multi_accept on;
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 4096m;
client_body_buffer_size 1k;
client_body_timeout 10;
client_header_timeout 10;
send_timeout 10;
include /opt/local/etc/nginx/mime.types;
default_type application/octet-stream;
# mkdir /opt/local/etc/nginx/log
access_log /opt/local/etc/nginx/log/nginx_access.log;
error_log /opt/local/etc/nginx/log/nginx_error.log;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# mkdir /opt/local/etc/nginx/config
include /opt/local/etc/nginx/config/*;
# ssl does not seem to work in this method of installation
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"" >
<plist version='1.0'>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment