Skip to content

Instantly share code, notes, and snippets.

@stypr
Last active August 17, 2019 19:55
Show Gist options
  • Save stypr/ca75f6dab92339a61c90 to your computer and use it in GitHub Desktop.
Save stypr/ca75f6dab92339a61c90 to your computer and use it in GitHub Desktop.
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_pass 127.0.0.1:9000;
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 https://gist.github.com/renjunkui/1267057 for lower versions of MACOSX.

# install MacPorts at http://www.macports.org/install.php
user$ sudo su
Password:
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/nginx.pid;
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"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key><string>org.macports.nginx</string>
<key>UserName</key><string>root</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/daemondo</string>
<string>--label=nginx</string>
<string>--start-cmd</string>
<string>/opt/local/sbin/nginx</string>
<string>;</string>
<string>--pid=fileauto</string>
<string>--pidfile</string>
<string>/opt/local/var/run/nginx/nginx.pid</string>
</array>
<key>Debug</key><false/>
<key>Disabled</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PHP_FCGI_CHILDREN</key>
<string>5</string>
<key>PHP_FCGI_MAX_REQUESTS</key>
<string>1000</string>
</dict>
<key>UserName</key><string>root</string>
<key>Label</key>
<string>org.macports.php-fastcgi</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/php-cgi</string>
<string>-b127.0.0.1:9000</string>
<string>-q</string>
</array>
<key>KeepALive</key><true/>
<key>RunAtLoad</key><true/>
<key>Debug</key><false/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment