Skip to content

Commit f1377d1

Browse files
Add PHP-FPM conf and tuning settings (#1496)
Allows customization of the PHP-FPM service configuration. Previously only the _pool_ configuration was exposed in Trellis. This allows for more advanced performance tuning. The PHP-FPM php.ini template is the default values as a starting point. Co-authored-by: Paul Brzeski <[email protected]>
1 parent c9f4dd9 commit f1377d1

File tree

5 files changed

+168
-2
lines changed

5 files changed

+168
-2
lines changed

roles/php/defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ php_opcache_max_accelerated_files: 4000
3131
php_opcache_memory_consumption: 128
3232
php_opcache_revalidate_freq: 60
3333
php_opcache_validate_timestamps: 1
34+
35+
php_fpm_set_emergency_restart_threshold: false
36+
php_fpm_emergency_restart_threshold: 0
37+
php_fpm_set_emergency_restart_interval: false
38+
php_fpm_emergency_restart_interval: 0
39+
php_fpm_set_process_control_timeout: false
40+
php_fpm_process_control_timeout: 0

roles/php/tasks/main.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@
4242
state: started
4343
enabled: true
4444

45-
- name: Copy PHP-FPM configuration file
45+
- name: Copy PHP-FPM php.ini file
4646
template:
4747
src: php-fpm.ini.j2
4848
dest: /etc/php/{{ php_version }}/fpm/php.ini
4949
mode: '0644'
50+
51+
- name: Copy PHP-FPM configuration file
52+
template:
53+
src: php-fpm.conf.j2
54+
dest: /etc/php/{{ php_version }}/fpm/php-fpm.conf
55+
mode: '0644'
5056
notify: reload php-fpm
5157

5258
- name: Copy PHP CLI configuration file

roles/php/templates/php-fpm.conf.j2

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
; {{ ansible_managed }}
2+
3+
;;;;;;;;;;;;;;;;;;;;;
4+
; FPM Configuration ;
5+
;;;;;;;;;;;;;;;;;;;;;
6+
7+
; All relative paths in this configuration file are relative to PHP's install
8+
; prefix (/usr). This prefix can be dynamically changed by using the
9+
; '-p' argument from the command line.
10+
11+
;;;;;;;;;;;;;;;;;;
12+
; Global Options ;
13+
;;;;;;;;;;;;;;;;;;
14+
15+
[global]
16+
; Pid file
17+
; Note: the default prefix is /var
18+
; Default Value: none
19+
; Warning: if you change the value here, you need to modify systemd
20+
; service PIDFile= setting to match the value here.
21+
pid = /run/php/php{{ php_version }}-fpm.pid
22+
23+
; Error log file
24+
; If it's set to "syslog", log is sent to syslogd instead of being written
25+
; into a local file.
26+
; Note: the default prefix is /var
27+
; Default Value: log/php-fpm.log
28+
error_log = /var/log/php{{ php_version }}-fpm.log
29+
30+
; syslog_facility is used to specify what type of program is logging the
31+
; message. This lets syslogd specify that messages from different facilities
32+
; will be handled differently.
33+
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
34+
; Default Value: daemon
35+
;syslog.facility = daemon
36+
37+
; syslog_ident is prepended to every message. If you have multiple FPM
38+
; instances running on the same server, you can change the default value
39+
; which must suit common needs.
40+
; Default Value: php-fpm
41+
;syslog.ident = php-fpm
42+
43+
; Log level
44+
; Possible Values: alert, error, warning, notice, debug
45+
; Default Value: notice
46+
;log_level = notice
47+
48+
; Log limit on number of characters in the single line (log entry). If the
49+
; line is over the limit, it is wrapped on multiple lines. The limit is for
50+
; all logged characters including message prefix and suffix if present. However
51+
; the new line character does not count into it as it is present only when
52+
; logging to a file descriptor. It means the new line character is not present
53+
; when logging to syslog.
54+
; Default Value: 1024
55+
;log_limit = 4096
56+
57+
; Log buffering specifies if the log line is buffered which means that the
58+
; line is written in a single write operation. If the value is false, then the
59+
; data is written directly into the file descriptor. It is an experimental
60+
; option that can potentionaly improve logging performance and memory usage
61+
; for some heavy logging scenarios. This option is ignored if logging to syslog
62+
; as it has to be always buffered.
63+
; Default value: yes
64+
;log_buffering = no
65+
66+
; If this number of child processes exit with SIGSEGV or SIGBUS within the time
67+
; interval set by emergency_restart_interval then FPM will restart. A value
68+
; of '0' means 'Off'.
69+
; Default Value: 0
70+
{% if php_fpm_set_emergency_restart_threshold %}
71+
emergency_restart_threshold = {{ php_fpm_emergency_restart_threshold }}
72+
{% endif %}
73+
74+
; Interval of time used by emergency_restart_interval to determine when
75+
; a graceful restart will be initiated. This can be useful to work around
76+
; accidental corruptions in an accelerator's shared memory.
77+
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
78+
; Default Unit: seconds
79+
; Default Value: 0
80+
{% if php_fpm_set_emergency_restart_interval %}
81+
emergency_restart_interval = {{ php_fpm_emergency_restart_interval }}
82+
{% endif %}
83+
84+
; Time limit for child processes to wait for a reaction on signals from master.
85+
; Available units: s(econds), m(inutes), h(ours), or d(ays)
86+
; Default Unit: seconds
87+
; Default Value: 0
88+
{% if php_fpm_set_process_control_timeout %}
89+
process_control_timeout = {{ php_fpm_process_control_timeout }}
90+
{% endif %}
91+
92+
; The maximum number of processes FPM will fork. This has been designed to control
93+
; the global number of processes when using dynamic PM within a lot of pools.
94+
; Use it with caution.
95+
; Note: A value of 0 indicates no limit
96+
; Default Value: 0
97+
; process.max = 128
98+
99+
; Specify the nice(2) priority to apply to the master process (only if set)
100+
; The value can vary from -19 (highest priority) to 20 (lowest priority)
101+
; Note: - It will only work if the FPM master process is launched as root
102+
; - The pool process will inherit the master process priority
103+
; unless specified otherwise
104+
; Default Value: no set
105+
; process.priority = -19
106+
107+
; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
108+
; Default Value: yes
109+
;daemonize = yes
110+
111+
; Set open file descriptor rlimit for the master process.
112+
; Default Value: system defined value
113+
;rlimit_files = 1024
114+
115+
; Set max core size rlimit for the master process.
116+
; Possible Values: 'unlimited' or an integer greater or equal to 0
117+
; Default Value: system defined value
118+
;rlimit_core = 0
119+
120+
; Specify the event mechanism FPM will use. The following is available:
121+
; - select (any POSIX os)
122+
; - poll (any POSIX os)
123+
; - epoll (linux >= 2.5.44)
124+
; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
125+
; - /dev/poll (Solaris >= 7)
126+
; - port (Solaris >= 10)
127+
; Default Value: not set (auto detection)
128+
;events.mechanism = epoll
129+
130+
; When FPM is built with systemd integration, specify the interval,
131+
; in seconds, between health report notification to systemd.
132+
; Set to 0 to disable.
133+
; Available Units: s(econds), m(inutes), h(ours)
134+
; Default Unit: seconds
135+
; Default value: 10
136+
;systemd_interval = 10
137+
138+
;;;;;;;;;;;;;;;;;;;;
139+
; Pool Definitions ;
140+
;;;;;;;;;;;;;;;;;;;;
141+
142+
; Multiple pools of child processes may be started with different listening
143+
; ports and different management options. The name of the pool will be
144+
; used in logs and stats. There is no limitation on the number of pools which
145+
; FPM can handle. Your system will tell you anyway :)
146+
147+
; Include one or more files. If glob(3) exists, it is used to include a bunch of
148+
; files from a glob(3) pattern. This directive can be used everywhere in the
149+
; file.
150+
; Relative path can also be used. They will be prefixed by:
151+
; - the global prefix if it's been set (-p argument)
152+
; - /usr otherwise
153+
include=/etc/php/{{ php_version }}/fpm/pool.d/*.conf

roles/wordpress-setup/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
- name: Create WordPress php-fpm configuration file
2929
template:
30-
src: php-fpm.conf.j2
30+
src: php-fpm-pool-wordpress.conf.j2
3131
dest: /etc/php/{{ php_version }}/fpm/pool.d/wordpress.conf
3232
mode: '0644'
3333
notify: reload php-fpm

0 commit comments

Comments
 (0)