Skip to content

Instantly share code, notes, and snippets.

@cbednarski
Last active January 11, 2019 12:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cbednarski/6504006 to your computer and use it in GitHub Desktop.
Save cbednarski/6504006 to your computer and use it in GitHub Desktop.
Nginx and php-fpm configs for local development
server {
listen 8080;
server_name local.webblob.com;
root /Users/cbednarski/code/WebBlob/src;
error_page 403 /403.html;
error_page 404 /404.html;
error_page 500 /500.html;
error_page 502 /502.html;
error_page 503 /503.html;
error_page 504 /504.html;
location / {
index index.html index.htm;
try_files $uri /index.php;
}
# Handles generic .php files
location ~ \.php$ {
fastcgi_pass unix:/usr/local/var/php-fpm.sock;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
# Handles a front-controller
location /index.php {
fastcgi_pass unix:/usr/local/var/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_intercept_errors on;
}
location ~ /([0-9][0-9][0-9]).html {
try_files $1.html @error;
internal;
}
location @error {
# see: https://github.com/cbednarski/slick-error-pages
root /Users/cbednarski/code/slick-error-pages;
}
}
[global]
pid = /usr/local/var/run/php-fpm.pid
error_log = /usr/local/var/log/php/5.4/php_fpm.error.log
daemonize = no
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10s
[www]
listen = /usr/local/var/php-fpm.sock
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.status_path = /fpm_status
pm.max_children = 256
pm.start_servers = 25
pm.min_spare_servers = 5
pm.max_spare_servers = 50
pm.max_requests = 4000
slowlog = /usr/local/var/log/php/5.4/php_fpm.slow.log
request_slowlog_timeout = 10
request_terminate_timeout = 60
catch_workers_output = yes
php_value[date.timezone] = America/Los_Angeles
php_value[error_reporting] = E_ALL & ~E_STRICT
@cbednarski
Copy link
Author

Installing

Getting this running on OSX is a bit convoluted, but it works.

brew install php54 --with-fpm
brew install nginx

If you already have php installed you'll need to remove it and reinstall with --with-fpm.

Startup

Nginx backgrounds automatically so you'll need to pass -s to send it signals. php-fpm runs in the foreground (based on daemonize = no) so you can kill it with Ctrl-C.

nginx
nginx -s reload
nginx -s stop
/usr/local/Cellar/php54/5.4.19/sbin/php-fpm \
    -c /usr/local/etc/php/5.4/php.ini \
    -y /usr/local/etc/php/5.4/php-fpm.ini

@cbednarski
Copy link
Author

Also, it occurs to me that the php_value configs should be set in php.ini, not in the fpm configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment