• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
  • Created over 13 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A php-fpm example configuration for both UNIX and TCP sockets.

Example configuration of php-fpm

Introduction

This is an example configuration php-fpm which is the preferred way of serving PHP with FastCGI. The old php-cgi is deprecated. You can even use a patch for PHP versions prior to 5.3.3, when fpm become an official PHP project.

Generalities

The way that php-fpm operates is through a master process that launches children processes (workers) that serve the requests. These workers can be run under a particular user. Making it appropriate for environments where there are several users each one running their own set of PHP apps.

php-fpm is pretty much a work in progress, although on one hand is IMHO the best thing to come out of PHP land in a lot of time, still lacks a lot of nice features like graceful restarts. Currently adding a new pool or reloading the config requires a full restart. Which causes some downtime. Work is in progress to provide graceful restarts/reloads like Nginx has.

It has the capacity to adjust the number of workers dynamically to the load, varying from a minimum to a specified maximum.

Configuration layout

The configuration comes in two flavors:

  1. unix which is the default. It uses UNIX domain sockets for communication between the FCGI responder provided by php-fpm and the server or request frontend.

  2. tcp. It uses TCP sockets for communication between the FCGI responder provided by php-fpm and the server or request frontend.

Choose the one that is more appropriate for your setup. Up until PHP 5.3.8 TCP sockets, although, theoretically slower, if your setup is on the loopback, behave better than UNIX sockets for high-traffic sites.

This might have changed in 5.3.10 and 5.4.x. Try it and report back please.

Load adequation

There's no algorithm for determining the number of children. It depends on your application.

A thread in the highload-php-en gives some tips on how to determine the number of children.

  1. If your load is CPU bound then the rule is that the number of children should be equal to number of CPUs plus 20 %.

    Example: Machine with 8 CPUs. Number of children = 10.

  2. If your load is I/O bound then apply the following rule:

    number_of_children = 1.2 * total_memory / average_space_per_process 
    

    Example: PHP processes occupying 256 MB of average space in a machine with 2GB of RAM that can be used for running this PHP application.

    number_of_children = 1.2 * 2048 / 256 
    

    giving: 10 children.

    Determine the medium space occupied by a PHP process and apply the above formula. The 1.2 factor is just a security factor, to use a much abused engineering term.

Features

  1. It uses UNIX sockets for connections from the web server to the FastCGI daemon as the default. It provides a branch tcp that relies on TCP sockets. Choose which suits you better.

  2. The php.ini is modified from the stock one that comes with the Debian package. The modifications were made by using a tiny script that I wrote for cleaning up a PHP config and that's available here on github.

  3. There are three pools on this config that run under the www-data user. The idea is that the server should load balance and distribute the load as you wish over it.

  4. Support for the status and ping functionalities of php-fpm. See here how to enable it for Nginx.

Installation

  1. Clone the git repo: git://github.com/perusio/php-fpm-example-config.

  2. Checkout the tcp branch if that's suits you better:

     git checkout -b tcp 
    

    If on the contrary the unix sockets approach is more suited to your site(s) then you can ignore this step and proceed to 3 directly.

  3. Alter the php-fpm.conf and the pool.d/www.conf file to your liking. Add any pool that you might want.

  4. Copy the files to the destination directory:

    cp php5-fpm.conf /etc/php5/fpm

    cp -a pool.d /etc/php5/fpm

  5. (Re)start php5-fpm with service php5-fpm restart or service php5-fpm start if starting php-fpm anew.

Caveats

Remember to always do service php5-fpm restart after adding a new pool or modifying the configuration of an existing one.

More Repositories

1

drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
Nginx
855
star
2

nginx_ensite

A script to enable or disable a site in nginx.
Shell
556
star
3

wordpress-nginx

Nginx configuration for running WordPress
383
star
4

nginx-cache-purge

A bash script for deleting items from Nginx cache
Shell
245
star
5

nginx-hello-world-module

A hello world module for learning Nginx module development
C
195
star
6

linux-programming-by-example

C code from the book "Linux Programming by Example"
C
118
star
7

nginx-munin

A set of plugins for monitoring nginx with Munin
Perl
110
star
8

php-ini-cleanup

A script that cleans up the php.ini file with security in mind
Awk
106
star
9

nginx-auth-request-module

A Nginx module that enables authorizations on sub-requests
C
83
star
10

nginx-cache-inspector

Script that allows to inspect the Nginx cache
Shell
83
star
11

monit-miscellaneous

Monit configuration files for miscellaneous services
64
star
12

high-performance-web-kernel-parameters

A bunch of files with parameters for enabling a high performance web host
54
star
13

lua-resty-tarantool

Library for working with tarantool from nginx with the embedded Lua module or with Openresty
Lua
45
star
14

nginx-delay-module

Nginx module for inserting delays when serving requests.
C
38
star
15

redmine-nginx

A opinionated config for running Redmine with Nginx and thin.
35
star
16

chive-nginx

Running Chive with Nginx
27
star
17

nginx-spamhaus-drop

A shell script that creates a Nginx configuration for using Spamhaus DROP lists
Shell
26
star
18

php-fastcgi-debian-script

An init script to launch PHP the FastCGI daemon and spawn when needed in Debian
Shell
22
star
19

php-relaunch-web

Relaunch a PHP FPM and/or CGI process on timeout or termination
Shell
22
star
20

php-handlersocket

A PECL extension for using the HandlerSocket NoSQL MySQL plugin
PHP
18
star
21

add-etc-hosts

A script to add/remove hosts from the /etc/hosts file
Shell
15
star
22

squirrelmail-nginx

A secure and fast configuration for running squirrelmail with Nginx.
15
star
23

i3-config-dynamic-tagging

An opinionated i3 config with dynamic tagging
R
13
star
24

monit-graph

A PHP script for visualizing your servers Monit monitored services
PHP
13
star
25

nginx-http-concat

A Nginx module for concatenating files in a given context: CSS and JS files usually
12
star
26

drush-sql-extras

Various drush extra commands
PHP
9
star
27

drupal-nginx-fast-x-accel-redirect

A Drupal module that provides fast private file transfer with Nginx
PHP
8
star
28

memcached-better-init-script

A better init script for memcached. Specific config dir and stats integration if memcached library tools are installed.
Shell
8
star
29

nginx-mdounin-patches

A couple of patches from Nginx connaisseur Maxim Dounin
8
star
30

nginx-load-balancing-extras

Nginx load balancing extra algorithms: sharded, consistent hashing
6
star
31

xorg-synaptics-led-support

Patches for supporting the LED in synaptics touchpads
6
star
32

drush-cache-warmer

A drush command implementing a cache warmer for keeping a cache primed. Adequate for Nginx cache and Varnish.
Lua
6
star
33

apache-mod_aclr-nginx-frontend

Apache mod_aclr: easy setup of Nginx as a frontend to Apache
C
5
star
34

munin-php-cgi

Munin plugin for monitoring PHP FastCGI Memory usage
4
star
35

drupal-db

A set of shell scripts for working with databases in Drupal
Shell
4
star
36

lml2-html5

The LML2 Common Lisp Markup Language with HTML5 support
Common Lisp
4
star
37

thttpd-config

thttpd config for using as an upstream CGI processor with Nginx
4
star
38

nginx-reverse-proxying-beyond

Nginx Reverse Proxying and Beyond Code
4
star
39

php-heartbeat

Simple script that functions as an hearbeat for PHP
PHP
4
star
40

kit

Guidelines for creating reusable features in Drupal
4
star
41

nginx-cache-simple-crawler

A script for keeping a bunch of static files in Nginx cache
Shell
3
star
42

docker-tarantool

Dockerfile setup for running tarantool in a secure and scalable way
Lua
3
star
43

lua-uri

A URI manipulation library written in pure Lua
Lua
3
star
44

filefield-nginx-progress

A drupal module for RFC1867 POST upload progress bar
PHP
3
star
45

memcached-inspect-keys

A script in Lua to inspect a memcached instance
Lua
3
star
46

drupal-nginx-aggregation

A drupal module for aggregating CSS and JS files using Nginx HTTP concat
PHP
3
star
47

drush-aliases

A shell script that defines a bunch of aliases for drush fun and profit
3
star
48

panels_extra_layouts

Extra layouts for the Drupal panels module
PHP
3
star
49

doxymacs-luadoc

Luadoc support for Doxymacs
Emacs Lisp
3
star
50

beautiful-invoicing

A simple invoicing software for producing beautiful invoices using LuaLaTeX
Lua
3
star
51

php-fpm-relaunch

A shell script to run as CGI in thttpd that (re)launches php-fpm on an Nginx 502
Shell
3
star
52

misc-git-hooks

Miscellaneous git hooks for fun and profit
Shell
2
star
53

commerce-examples

The drupal commerce examples module
PHP
2
star
54

nginx-get-source

A script that downloads a Nginx source tarball verifiying its signature
Shell
2
star
55

encrypt-file

A simple script for encrypting/decrypting a file using Triple DES
Shell
2
star
56

create-ssl-certificates

Helper scripts to create Certificate Signing Requests (CSR) and certifcate bundles - particularly useful for nginx
Shell
2
star
57

clips-cpp-interface

CLIPS C++ interface
C++
2
star
58

memcache-server-config-drupal

A multi-bin Memcache configuration for Drupal
2
star
59

nginx-debianization

nginx debianization using git-buildpackage for building a debian package
C
2
star
60

nginx-debian-package-build-helpers

A bunch of helper scripts to help me build my nginx debian package
Shell
2
star
61

angular-generate-urls-sitemap

Generates an URL list given an angular router - this makes sense only for static routes.
Awk
2
star
62

nginx_httpd_twiter_module

this is test nginx module
C
1
star
63

nginx-manpage

A nginx manpage written with ronn
1
star
64

yui_editor

The drupal module for the YUI Rich Text Editor
JavaScript
1
star
65

nginx-http-slice

Nginx module for serving a file in slices (reverse byte-range)
1
star
66

token

Forked version of the Drupal token module
PHP
1
star
67

apache-mod_helloworld

An hello world module for Apache 2.2
C
1
star
68

nginx-http-footer-filter

A nginx module that prints some text in the footer of a request
1
star
69

mkmf

A clone of the mkmf tool of HP-UX (Makefile creation for lazy programmers)
Perl
1
star
70

cg-training

The Commerce Guys training module
PHP
1
star
71

set-laptop-projector

A shell script for setting a projector with a laptop
Shell
1
star
72

lua-linenoise-debian-package

Debian packaging of the Lua linenoise binding.
C
1
star
73

google-weather-nginx-proxy

A script and Nginx configuration for getting Google Weather info on high traffic sites
PHP
1
star
74

nginx-fast-config

A simple helper module for running Drupal 6 with a 0 rewrites Nginx config
PHP
1
star
75

commerce-order-counter

A generic framework for setting the order number/code in Drupal Commerce or Commerce Kickstart.
PHP
1
star
76

perusio.github.com

My github page
JavaScript
1
star