1 |
40e46009
|
Scott Ullrich
|
#!/bin/sh
|
2 |
de96a790
|
Scott Ullrich
|
#
|
3 |
ac24dc24
|
Renato Botelho
|
# rc.php_ini_setup
|
4 |
|
|
#
|
5 |
|
|
# part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
# Copyright (c) 2014-2016 Electric Sheep Fencing
|
7 |
a68f7a3d
|
Luiz Otavio O Souza
|
# Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
8 |
ac24dc24
|
Renato Botelho
|
# All rights reserved.
|
9 |
|
|
#
|
10 |
b12ea3fb
|
Renato Botelho
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
11 |
|
|
# you may not use this file except in compliance with the License.
|
12 |
|
|
# You may obtain a copy of the License at
|
13 |
ac24dc24
|
Renato Botelho
|
#
|
14 |
b12ea3fb
|
Renato Botelho
|
# http://www.apache.org/licenses/LICENSE-2.0
|
15 |
ac24dc24
|
Renato Botelho
|
#
|
16 |
b12ea3fb
|
Renato Botelho
|
# Unless required by applicable law or agreed to in writing, software
|
17 |
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
18 |
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19 |
|
|
# See the License for the specific language governing permissions and
|
20 |
|
|
# limitations under the License.
|
21 |
ac24dc24
|
Renato Botelho
|
#
|
22 |
40e46009
|
Scott Ullrich
|
|
23 |
|
|
# Set our operating platform
|
24 |
c3f83348
|
Renato Botelho do Couto
|
VERSION=$(/bin/cat /etc/version)
|
25 |
5436d37a
|
Renato Botelho
|
MIN_REALMEM_FOR_OPCACHE=512
|
26 |
c44417f8
|
Scott Ullrich
|
|
27 |
903c1898
|
jim-p
|
if /usr/local/sbin/pkg-static info -e php83; then
|
28 |
44f72862
|
jim-p
|
EXTENSIONSDIR="/usr/local/lib/php/20230831/"
|
29 |
903c1898
|
jim-p
|
elif /usr/local/sbin/pkg-static info -e php82; then
|
30 |
e7e6a4ed
|
Marcello Coutinho
|
EXTENSIONSDIR="/usr/local/lib/php/20220829/"
|
31 |
|
|
elif /usr/local/sbin/pkg-static info -e php81; then
|
32 |
dfd11d44
|
Reid Linnemann
|
EXTENSIONSDIR="/usr/local/lib/php/20210902/"
|
33 |
|
|
elif /usr/local/sbin/pkg-static info -e php74; then
|
34 |
5586fce0
|
Renato Botelho do Couto
|
EXTENSIONSDIR="/usr/local/lib/php/20190902/"
|
35 |
|
|
elif /usr/local/sbin/pkg-static info -e php73; then
|
36 |
b2aae111
|
Renato Botelho
|
EXTENSIONSDIR="/usr/local/lib/php/20180731/"
|
37 |
cd91a57c
|
Renato Botelho do Couto
|
elif /usr/local/sbin/pkg-static info -e php72; then
|
38 |
ec29cf58
|
Renato Botelho
|
EXTENSIONSDIR="/usr/local/lib/php/20170718/"
|
39 |
|
|
fi
|
40 |
79454450
|
Scott Ullrich
|
|
41 |
0d60f50a
|
Seth Mos
|
# Grab amount of memory that is detected
|
42 |
47eee8fa
|
Scott Ullrich
|
if [ -f /var/log/dmesg.boot ]; then
|
43 |
c3f83348
|
Renato Botelho do Couto
|
AVAILMEM=$(/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}')
|
44 |
e173dd74
|
Phil Davis
|
else
|
45 |
c3f83348
|
Renato Botelho do Couto
|
AVAILMEM=$(/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}')
|
46 |
47eee8fa
|
Scott Ullrich
|
fi
|
47 |
c44417f8
|
Scott Ullrich
|
|
48 |
b713d790
|
Scott Ullrich
|
if [ -z "$AVAILMEM" ]; then
|
49 |
c3f83348
|
Renato Botelho do Couto
|
MEM=$(/sbin/sysctl -q hw.physmem | cut -d':' -f2)
|
50 |
|
|
AVAILMEM=$(/bin/expr $MEM / 1048576)
|
51 |
b713d790
|
Scott Ullrich
|
fi
|
52 |
|
|
|
53 |
73fa0178
|
Individual IT Services
|
|
54 |
|
|
# Get amount of ram installed on this system
|
55 |
c3f83348
|
Renato Botelho do Couto
|
REALMEM=$(/sbin/sysctl -q hw.realmem | /usr/bin/awk '{print $2/1048576}' | /usr/bin/awk -F '.' '{print $1}')
|
56 |
73fa0178
|
Individual IT Services
|
export REALMEM
|
57 |
|
|
export LOWMEM
|
58 |
|
|
|
59 |
5436d37a
|
Renato Botelho
|
if [ ${REALMEM} -lt $MIN_REALMEM_FOR_OPCACHE ]; then
|
60 |
73fa0178
|
Individual IT Services
|
LOWMEM="TRUE"
|
61 |
5436d37a
|
Renato Botelho
|
echo ">>> Under $MIN_REALMEM_FOR_OPCACHE megabytes of ram detected. Not enabling opcache"
|
62 |
|
|
echo ">>> Under $MIN_REALMEM_FOR_OPCACHE megabytes of ram detected. Not enabling opcache" | /usr/bin/logger -p daemon.info -i -t rc.php_ini_setup
|
63 |
73fa0178
|
Individual IT Services
|
else
|
64 |
|
|
|
65 |
5436d37a
|
Renato Botelho
|
# Calculate opcache memory size according
|
66 |
73fa0178
|
Individual IT Services
|
# to detected memory values
|
67 |
|
|
if [ "$AVAILMEM" -gt "135" ]; then
|
68 |
5436d37a
|
Renato Botelho
|
OPCACHEMEMSIZE="10"
|
69 |
73fa0178
|
Individual IT Services
|
fi
|
70 |
|
|
if [ "$AVAILMEM" -gt "256" ]; then
|
71 |
5436d37a
|
Renato Botelho
|
OPCACHEMEMSIZE="20"
|
72 |
73fa0178
|
Individual IT Services
|
fi
|
73 |
|
|
if [ "$AVAILMEM" -gt "384" ]; then
|
74 |
5436d37a
|
Renato Botelho
|
OPCACHEMEMSIZE="25"
|
75 |
73fa0178
|
Individual IT Services
|
fi
|
76 |
|
|
if [ "$AVAILMEM" -gt "512" ]; then
|
77 |
5436d37a
|
Renato Botelho
|
OPCACHEMEMSIZE="30"
|
78 |
73fa0178
|
Individual IT Services
|
fi
|
79 |
|
|
if [ "$AVAILMEM" -gt "784" ]; then
|
80 |
5436d37a
|
Renato Botelho
|
OPCACHEMEMSIZE="50"
|
81 |
73fa0178
|
Individual IT Services
|
fi
|
82 |
2b11ff4d
|
Scott Ullrich
|
fi
|
83 |
40e46009
|
Scott Ullrich
|
|
84 |
31c96a14
|
Scott Ullrich
|
# Set upload directory
|
85 |
dc61252a
|
Renato Botelho
|
UPLOADTMPDIR="/tmp"
|
86 |
31c96a14
|
Scott Ullrich
|
|
87 |
e173dd74
|
Phil Davis
|
# Define php modules. Do not add .so, it will
|
88 |
de96a790
|
Scott Ullrich
|
# be done automatically by the script below.
|
89 |
a4fc6ec7
|
Ermal
|
PHPMODULES="standard"
|
90 |
c25197ba
|
smos
|
# Config read/write
|
91 |
|
|
PHPMODULES="$PHPMODULES xml libxml dom"
|
92 |
e115bd22
|
Renato Botelho
|
PHPMODULES="$PHPMODULES SimpleXML xmlreader xmlwriter"
|
93 |
be1db1d3
|
Scott Ullrich
|
# Downloading via HTTP/FTP (pkg mgr, etc)
|
94 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES curl date"
|
95 |
e173dd74
|
Phil Davis
|
# Internationalization
|
96 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES gettext"
|
97 |
be1db1d3
|
Scott Ullrich
|
# User manager
|
98 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES ldap openssl pcntl"
|
99 |
b3765f4c
|
Roberto Nunnari
|
PHPMODULES="$PHPMODULES mcrypt"
|
100 |
be1db1d3
|
Scott Ullrich
|
# Regexs, PERL style!
|
101 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES pcre"
|
102 |
be1db1d3
|
Scott Ullrich
|
# The mighty posix!
|
103 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES posix"
|
104 |
|
|
PHPMODULES="$PHPMODULES readline"
|
105 |
be1db1d3
|
Scott Ullrich
|
# Login sessions
|
106 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES session"
|
107 |
fca48a65
|
Scott Ullrich
|
# Firewall rules edit
|
108 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES ctype"
|
109 |
16058a05
|
Scott Ullrich
|
# firewall_rules_edit.php
|
110 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES mbstring"
|
111 |
|
|
# Synchronization primitives
|
112 |
|
|
PHPMODULES="$PHPMODULES shmop"
|
113 |
be1db1d3
|
Scott Ullrich
|
# Page compression
|
114 |
5556f3a1
|
Ermal
|
PHPMODULES="$PHPMODULES zlib"
|
115 |
|
|
# SQLlite & Database
|
116 |
|
|
PHPMODULES="$PHPMODULES spl"
|
117 |
e115bd22
|
Renato Botelho
|
PHPMODULES="$PHPMODULES PDO"
|
118 |
6f657dfd
|
Renato Botelho
|
PHPMODULES="$PHPMODULES sqlite3"
|
119 |
04747c75
|
Warren Baker
|
# RADIUS
|
120 |
|
|
PHPMODULES="$PHPMODULES radius"
|
121 |
5556f3a1
|
Ermal
|
# pfSense extensions
|
122 |
|
|
PHPMODULES="$PHPMODULES pfSense"
|
123 |
a1f77238
|
Darren Embry
|
# json
|
124 |
|
|
PHPMODULES="$PHPMODULES json"
|
125 |
c1993935
|
jim-p
|
# bcmath
|
126 |
|
|
PHPMODULES="$PHPMODULES bcmath"
|
127 |
c28da0a7
|
Matt Smith
|
# filter
|
128 |
|
|
PHPMODULES="$PHPMODULES filter"
|
129 |
475f0b6d
|
Renato Botelho
|
# rrd
|
130 |
|
|
PHPMODULES="$PHPMODULES rrd"
|
131 |
e83dca8c
|
Scott Ullrich
|
|
132 |
aee36a29
|
Renato Botelho
|
PHP_ZEND_MODULES=""
|
133 |
8ef700da
|
Scott Ullrich
|
|
134 |
80d887d1
|
Scott Ullrich
|
# Modules previously included.
|
135 |
fcdf9492
|
Scott Ullrich
|
# can be turned on by touching
|
136 |
80d887d1
|
Scott Ullrich
|
# /etc/php_dynamodules/$modulename
|
137 |
|
|
# sysvmsg \
|
138 |
|
|
# sysvsem \
|
139 |
|
|
# sysvshm \
|
140 |
|
|
# bcmath \
|
141 |
|
|
# tokenizer \
|
142 |
|
|
# uploadprogress \
|
143 |
|
|
# sockets \
|
144 |
|
|
# Reflection \
|
145 |
|
|
# mysql \
|
146 |
|
|
# bz2 \
|
147 |
|
|
|
148 |
5556f3a1
|
Ermal
|
# Clear the .ini file to make sure we are clean
|
149 |
69b27c16
|
Scott Ullrich
|
if [ -f /usr/local/etc/php.ini ]; then
|
150 |
51d0f816
|
Ermal
|
/bin/rm /usr/local/etc/php.ini
|
151 |
69b27c16
|
Scott Ullrich
|
fi
|
152 |
c3f83348
|
Renato Botelho do Couto
|
LOADED_MODULES=$(/usr/local/bin/php-cgi -m | /usr/bin/grep -v "\[")
|
153 |
e83dca8c
|
Scott Ullrich
|
|
154 |
a5c36eb2
|
Renato Botelho
|
unset TIMEZONE
|
155 |
339b8893
|
Renato Botelho
|
# Fetch the timezone from /var/db/zoneinfo if present
|
156 |
|
|
if [ -f /var/db/zoneinfo ]; then
|
157 |
|
|
TIMEZONE=$(cat /var/db/zoneinfo)
|
158 |
a5c36eb2
|
Renato Botelho
|
fi
|
159 |
|
|
|
160 |
|
|
if [ -z "${TIMEZONE}" ]; then
|
161 |
|
|
# Second option is from config.xml
|
162 |
|
|
TIMEZONE=$(/usr/local/sbin/read_xml_tag.sh string system/timezone)
|
163 |
|
|
fi
|
164 |
|
|
|
165 |
|
|
if [ -z "${TIMEZONE}" ]; then
|
166 |
e4121dde
|
Renato Botelho
|
# Last option, use default value from $g or Etc/UTC
|
167 |
|
|
TIMEZONE=$(/usr/local/sbin/read_global_var default_timezone "Etc/UTC")
|
168 |
a5c36eb2
|
Renato Botelho
|
fi
|
169 |
|
|
|
170 |
45c4bc38
|
Renato Botelho
|
if echo "${VERSION}" | grep -q RELEASE; then
|
171 |
9d78a172
|
jim-p
|
# On release versions, reduce error reporting and don't print function arguments.
|
172 |
45c4bc38
|
Renato Botelho
|
error_reporting="error_reporting = E_ERROR | E_PARSE"
|
173 |
9d78a172
|
jim-p
|
exception_ignore_args="zend.exception_ignore_args=1"
|
174 |
45c4bc38
|
Renato Botelho
|
else
|
175 |
9d78a172
|
jim-p
|
# On development versions, increase error reporting and print function arguments.
|
176 |
926479e8
|
Reid Linnemann
|
error_reporting="error_reporting = E_ALL ^ (E_WARNING | E_NOTICE | E_DEPRECATED)"
|
177 |
9d78a172
|
jim-p
|
exception_ignore_args="zend.exception_ignore_args=0"
|
178 |
45c4bc38
|
Renato Botelho
|
fi
|
179 |
|
|
|
180 |
5556f3a1
|
Ermal
|
# Get a loaded module list in the stock php
|
181 |
2ed3203c
|
Scott Ullrich
|
# Populate a dummy php.ini to avoid
|
182 |
|
|
# the file being clobbered and the firewall
|
183 |
|
|
# not being able to boot back up.
|
184 |
3646fbcb
|
Renato Botelho
|
/bin/cat >/usr/local/etc/php.ini <<EOF
|
185 |
4b29393a
|
Scott Ullrich
|
; File generated from /etc/rc.php_ini_setup
|
186 |
40e46009
|
Scott Ullrich
|
output_buffering = "0"
|
187 |
|
|
expose_php = Off
|
188 |
|
|
implicit_flush = true
|
189 |
|
|
magic_quotes_gpc = Off
|
190 |
9d0be827
|
smos
|
max_execution_time = 900
|
191 |
062a5434
|
Chris Buechler
|
request_terminate_timeout = 900
|
192 |
7e824233
|
smos
|
max_input_time = 1800
|
193 |
e56374a8
|
NewEraCracker
|
max_input_vars = 5000
|
194 |
40e46009
|
Scott Ullrich
|
register_argc_argv = On
|
195 |
aa205c3b
|
Ermal
|
register_long_arrays = Off
|
196 |
362ec35d
|
Ermal
|
variables_order = "GPCS"
|
197 |
40e46009
|
Scott Ullrich
|
file_uploads = On
|
198 |
31c96a14
|
Scott Ullrich
|
upload_tmp_dir = ${UPLOADTMPDIR}
|
199 |
96325dba
|
Warren Baker
|
upload_max_filesize = 200M
|
200 |
|
|
post_max_size = 200M
|
201 |
40e46009
|
Scott Ullrich
|
html_errors = Off
|
202 |
f4015bd7
|
Scott Ullrich
|
zlib.output_compression = Off
|
203 |
40e46009
|
Scott Ullrich
|
zlib.output_compression_level = 1
|
204 |
7e0da288
|
Christian McDonald
|
include_path = ".:/etc/inc:/usr/local/pfSense/include:/usr/local/pfSense/include/www:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg:/usr/local/www/classes:/usr/local/www/classes/Form:/usr/local/share/pear:/usr/local/share/openssl_x509_crl/"
|
205 |
926479e8
|
Reid Linnemann
|
display_startup_errors=off
|
206 |
9d78a172
|
jim-p
|
; No need to display errors directly, they are handled in etc/inc/config.lib.inc by pfSense_clear_globals()
|
207 |
|
|
display_errors=off
|
208 |
baa2dba2
|
Scott Ullrich
|
log_errors=on
|
209 |
|
|
error_log=/tmp/PHP_errors.log
|
210 |
0804f515
|
Scott Ullrich
|
extension_dir=${EXTENSIONSDIR}
|
211 |
9d0be827
|
smos
|
date.timezone="${TIMEZONE}"
|
212 |
3e582e4f
|
NewEraCracker
|
session.hash_bits_per_character = 5
|
213 |
|
|
session.hash_function = 1
|
214 |
45c4bc38
|
Renato Botelho
|
${error_reporting}
|
215 |
9d78a172
|
jim-p
|
${exception_ignore_args}
|
216 |
40e46009
|
Scott Ullrich
|
|
217 |
4b29393a
|
Scott Ullrich
|
; Extensions
|
218 |
a8e61346
|
Ermal
|
|
219 |
40e46009
|
Scott Ullrich
|
EOF
|
220 |
|
|
|
221 |
e83dca8c
|
Scott Ullrich
|
# Loop through and generate modules to load.
|
222 |
|
|
# Take into account modules built into php.
|
223 |
|
|
for EXT in $PHPMODULES; do
|
224 |
|
|
SHOULDADD="true"
|
225 |
de96a790
|
Scott Ullrich
|
# Check to see if module is compiled into php statically
|
226 |
e83dca8c
|
Scott Ullrich
|
for LM in $LOADED_MODULES; do
|
227 |
|
|
if [ "$EXT" = "$LM" ]; then
|
228 |
|
|
SHOULDADD="false"
|
229 |
|
|
fi
|
230 |
|
|
done
|
231 |
|
|
if [ "$SHOULDADD" = "true" ]; then
|
232 |
de96a790
|
Scott Ullrich
|
# Ensure extension exists before adding.
|
233 |
69b27c16
|
Scott Ullrich
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
234 |
3646fbcb
|
Renato Botelho
|
echo "extension=${EXT}.so" >> /usr/local/etc/php.ini
|
235 |
0804f515
|
Scott Ullrich
|
fi
|
236 |
e83dca8c
|
Scott Ullrich
|
fi
|
237 |
|
|
done
|
238 |
|
|
|
239 |
8ef700da
|
Scott Ullrich
|
# Zend modules
|
240 |
|
|
for EXT in $PHP_ZEND_MODULES; do
|
241 |
|
|
# Ensure extension exists before adding.
|
242 |
aee36a29
|
Renato Botelho
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
243 |
3646fbcb
|
Renato Botelho
|
echo "zend_extension=${EXT}.so" >> /usr/local/etc/php.ini
|
244 |
8ef700da
|
Scott Ullrich
|
fi
|
245 |
|
|
done
|
246 |
|
|
|
247 |
73fa0178
|
Individual IT Services
|
if [ "$LOWMEM" != "TRUE" ]; then
|
248 |
40e46009
|
Scott Ullrich
|
|
249 |
3646fbcb
|
Renato Botelho
|
/bin/cat >>/usr/local/etc/php.ini <<EOF
|
250 |
e83dca8c
|
Scott Ullrich
|
|
251 |
5436d37a
|
Renato Botelho
|
; opcache Settings
|
252 |
|
|
opcache.enabled="1"
|
253 |
|
|
opcache.enable_cli="0"
|
254 |
|
|
opcache.memory_consumption="${OPCACHEMEMSIZE}"
|
255 |
40e46009
|
Scott Ullrich
|
|
256 |
a5c53d26
|
Renato Botelho
|
EOF
|
257 |
|
|
else
|
258 |
3646fbcb
|
Renato Botelho
|
/bin/cat >>/usr/local/etc/php.ini <<EOF
|
259 |
a5c53d26
|
Renato Botelho
|
; opcache Settings
|
260 |
|
|
opcache.enabled="0"
|
261 |
5556f3a1
|
Ermal
|
EOF
|
262 |
|
|
fi
|
263 |
|
|
|
264 |
e521e546
|
Christopher
|
# Memory limits 128M to calculated max
|
265 |
fc62ac50
|
Christopher
|
PHP_MEMORY_LIMIT="$(read_xml_tag.sh number system/php_memory_limit)"
|
266 |
|
|
|
267 |
e521e546
|
Christopher
|
# Set local variable for available memory to match the PHP code which always pulls from sysctl
|
268 |
|
|
MEM=$(/bin/expr $(/sbin/sysctl -q hw.physmem | cut -d':' -f2) / 1048576)
|
269 |
|
|
|
270 |
|
|
# Calculate MAX memory in the same fashion as get_php_max_memory() in /etc/inc/util.inc
|
271 |
|
|
let PHP_MAX_LIMIT=${MEM}-512
|
272 |
|
|
|
273 |
|
|
if [ "${PHP_MAX_LIMIT}" -le "0" ]; then
|
274 |
|
|
let PHP_MAX_LIMIT=${MEM}-128
|
275 |
|
|
|
276 |
|
|
if [ "${PHP_MAX_LIMIT}" -lt "128" ]; then
|
277 |
|
|
PHP_MAX_LIMIT=128
|
278 |
|
|
fi
|
279 |
|
|
fi
|
280 |
|
|
|
281 |
|
|
# If outside of limits, revert to default in same fashion as get_php_default_memory() in /etc/inc/util.inc
|
282 |
|
|
if ! { [ -n "${PHP_MEMORY_LIMIT}" ] && [ "${PHP_MEMORY_LIMIT}" -ge "128" ] && [ "${PHP_MEMORY_LIMIT}" -le "${PHP_MAX_LIMIT}" ]; }; then
|
283 |
|
|
if [ "$(uname -m)" == "amd64" ]; then
|
284 |
|
|
PHP_MEMORY_LIMIT=512
|
285 |
|
|
else
|
286 |
|
|
PHP_MEMORY_LIMIT=128
|
287 |
|
|
fi
|
288 |
|
|
|
289 |
|
|
if [ ${PHP_MEMORY_LIMIT} -ge "${MEM}" ]; then
|
290 |
|
|
let PHP_MEMORY_LIMIT=${MEM}/2
|
291 |
|
|
if [ "${PHP_MEMORY_LIMIT}" -lt "128" ]; then
|
292 |
|
|
PHP_MEMORY_LIMIT=128
|
293 |
|
|
fi
|
294 |
|
|
fi
|
295 |
fc62ac50
|
Christopher
|
fi
|
296 |
|
|
|
297 |
e521e546
|
Christopher
|
/bin/cat >>/usr/local/etc/php.ini <<EOF
|
298 |
|
|
memory_limit="${PHP_MEMORY_LIMIT}M"
|
299 |
|
|
EOF
|
300 |
|
|
|
301 |
6d7ee1ab
|
Ermal
|
PHPFPMMAX=3
|
302 |
2c131b10
|
marjohn56
|
PHPFPMIDLE=30
|
303 |
|
|
PHPFPMSTART=1
|
304 |
|
|
PHPFPMSPARE=2
|
305 |
|
|
PHPFPMREQ=500
|
306 |
7b03748b
|
Ermal
|
if [ $REALMEM -lt 250 ]; then
|
307 |
6d7ee1ab
|
Ermal
|
PHPFPMMAX=2
|
308 |
2c131b10
|
marjohn56
|
PHPFPMIDLE=5
|
309 |
|
|
PHPFPMSTART=1
|
310 |
|
|
PHPFPMSPARE=1
|
311 |
|
|
PHPFPMREQ=500
|
312 |
4aea91d8
|
Ermal
|
elif [ ${REALMEM} -gt 1000 ]; then
|
313 |
2c131b10
|
marjohn56
|
PHPFPMMAX=8
|
314 |
|
|
PHPFPMIDLE=3600
|
315 |
|
|
PHPFPMSTART=2
|
316 |
|
|
PHPFPMSPARE=7
|
317 |
179377b0
|
robjarsen
|
PHPFPMREQ=5000
|
318 |
4aea91d8
|
Ermal
|
fi
|
319 |
|
|
|
320 |
|
|
/bin/cat > /usr/local/lib/php-fpm.conf <<EOF
|
321 |
|
|
|
322 |
|
|
[global]
|
323 |
|
|
pid = run/php-fpm.pid
|
324 |
|
|
error_log=syslog
|
325 |
|
|
syslog.facility = daemon
|
326 |
9e0fb701
|
Ermal
|
syslog.ident = system
|
327 |
3ffae79b
|
Ermal
|
log_level = error
|
328 |
4aea91d8
|
Ermal
|
daemonize = yes
|
329 |
|
|
events.mechanism = kqueue
|
330 |
|
|
process.max = ${PHPFPMMAX}
|
331 |
|
|
|
332 |
40880eec
|
Renato Botelho
|
[nginx]
|
333 |
4aea91d8
|
Ermal
|
user = root
|
334 |
|
|
group = wheel
|
335 |
|
|
;mode = 0600
|
336 |
|
|
|
337 |
|
|
listen = /var/run/php-fpm.socket
|
338 |
|
|
listen.owner = root
|
339 |
|
|
listen.group = wheel
|
340 |
|
|
listen.mode = 0600
|
341 |
|
|
|
342 |
|
|
security.limit_extensions =
|
343 |
|
|
|
344 |
5293c5c7
|
Warren Baker
|
; Pass environment variables
|
345 |
|
|
env[PATH] = /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
346 |
75b8eb83
|
Renato Botelho
|
env[LOGNAME] = root
|
347 |
5293c5c7
|
Warren Baker
|
|
348 |
4aea91d8
|
Ermal
|
EOF
|
349 |
|
|
|
350 |
5be2085a
|
Ermal
|
if [ $REALMEM -lt 350 ]; then
|
351 |
4aea91d8
|
Ermal
|
/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
|
352 |
|
|
|
353 |
|
|
pm = ondemand
|
354 |
2c131b10
|
marjohn56
|
pm.process_idle_timeout = $PHPFPMIDLE
|
355 |
6d7ee1ab
|
Ermal
|
pm.max_children = $PHPFPMMAX
|
356 |
2c131b10
|
marjohn56
|
pm.max_requests = $PHPFPMREQ
|
357 |
4aea91d8
|
Ermal
|
EOF
|
358 |
|
|
|
359 |
|
|
elif [ $REALMEM -gt 1000 ]; then
|
360 |
|
|
/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
|
361 |
|
|
|
362 |
|
|
pm = dynamic
|
363 |
2c131b10
|
marjohn56
|
pm.process_idle_timeout = $PHPFPMIDLE
|
364 |
6d7ee1ab
|
Ermal
|
pm.max_children = $PHPFPMMAX
|
365 |
2c131b10
|
marjohn56
|
pm.start_servers = $PHPFPMSTART
|
366 |
|
|
pm.max_requests = $PHPFPMREQ
|
367 |
4aea91d8
|
Ermal
|
pm.min_spare_servers=1
|
368 |
2c131b10
|
marjohn56
|
pm.max_spare_servers= $PHPFPMSPARE
|
369 |
|
|
|
370 |
4aea91d8
|
Ermal
|
EOF
|
371 |
|
|
else
|
372 |
|
|
|
373 |
|
|
/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
|
374 |
|
|
|
375 |
|
|
pm = static
|
376 |
6d7ee1ab
|
Ermal
|
pm.max_children = $PHPFPMMAX
|
377 |
2c131b10
|
marjohn56
|
pm.max_requests = $PHPFPMREQ
|
378 |
4aea91d8
|
Ermal
|
EOF
|
379 |
|
|
|
380 |
|
|
fi
|
381 |
|
|
|
382 |
418fdfb3
|
PiBa-NL
|
# Add status url for php-fpm this will only be made available from localhost through nginx 'allow 127.0.0.1'
|
383 |
|
|
/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
|
384 |
|
|
pm.status_path = /status
|
385 |
|
|
|
386 |
|
|
EOF
|
387 |
|
|
|
388 |
e1fda0c0
|
Scott Ullrich
|
# Remove old log file if it exists.
|
389 |
|
|
if [ -f /var/run/php_modules_load_errors.txt ]; then
|
390 |
51d0f816
|
Ermal
|
/bin/rm /var/run/php_modules_load_errors.txt
|
391 |
e173dd74
|
Phil Davis
|
fi
|
392 |
e1fda0c0
|
Scott Ullrich
|
|
393 |
7030262c
|
Scott Ullrich
|
for EXT in $PHPMODULES; do
|
394 |
c3f83348
|
Renato Botelho do Couto
|
PHPMODULESLC="$PHPMODULESLC $(echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]')"
|
395 |
7030262c
|
Scott Ullrich
|
done
|
396 |
|
|
|
397 |
e1fda0c0
|
Scott Ullrich
|
# Check loaded modules and remove anything that did not load correctly
|
398 |
c3f83348
|
Renato Botelho do Couto
|
LOADED_MODULES=$(/usr/local/bin/php-cgi -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\[")
|
399 |
7030262c
|
Scott Ullrich
|
for EXT in $PHPMODULESLC; do
|
400 |
e1fda0c0
|
Scott Ullrich
|
SHOULDREMOVE="true"
|
401 |
|
|
for LM in $LOADED_MODULES; do
|
402 |
|
|
if [ "$EXT" = "$LM" ]; then
|
403 |
|
|
SHOULDREMOVE="false"
|
404 |
14dd1631
|
Renato Botelho
|
break
|
405 |
e173dd74
|
Phil Davis
|
fi
|
406 |
e1fda0c0
|
Scott Ullrich
|
done
|
407 |
1e86e897
|
Scott Ullrich
|
# Handle low memory situations
|
408 |
8ee1dc80
|
Scott Ullrich
|
if [ "$LOWMEM" = "TRUE" ]; then
|
409 |
5436d37a
|
Renato Botelho
|
if [ "$EXT" = "opcache" ]; then
|
410 |
8ee1dc80
|
Scott Ullrich
|
SHOULDREMOVE="true"
|
411 |
|
|
fi
|
412 |
|
|
if [ "$EXT" = "xcache" ]; then
|
413 |
|
|
SHOULDREMOVE="true"
|
414 |
|
|
fi
|
415 |
|
|
fi
|
416 |
e1fda0c0
|
Scott Ullrich
|
if [ "$SHOULDREMOVE" = "true" ]; then
|
417 |
|
|
if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
|
418 |
|
|
echo ">>> ${EXT} did not load correctly. Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
|
419 |
3646fbcb
|
Renato Botelho
|
/bin/cat /usr/local/etc/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
|
420 |
|
|
/bin/rm -f /usr/local/etc/php.ini
|
421 |
|
|
/bin/mv /tmp/php.ini /usr/local/etc/php.ini
|
422 |
e1fda0c0
|
Scott Ullrich
|
fi
|
423 |
|
|
fi
|
424 |
|
|
done
|