Project

General

Profile

Download (9.41 KB) Statistics
| Branch: | Tag: | Revision:
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
# Copyright (c) 2014-2019 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 45c4bc38 Renato Botelho
VERSION=`/bin/cat /etc/version`
25 5436d37a Renato Botelho
MIN_REALMEM_FOR_OPCACHE=512
26 c44417f8 Scott Ullrich
27 cd91a57c Renato Botelho do Couto
if /usr/local/sbin/pkg-static info -e php73; then
28 b2aae111 Renato Botelho
	EXTENSIONSDIR="/usr/local/lib/php/20180731/"
29 cd91a57c Renato Botelho do Couto
elif /usr/local/sbin/pkg-static info -e php72; then
30 ec29cf58 Renato Botelho
	EXTENSIONSDIR="/usr/local/lib/php/20170718/"
31
fi
32 79454450 Scott Ullrich
33 0d60f50a Seth Mos
# Grab amount of memory that is detected
34 47eee8fa Scott Ullrich
if [ -f /var/log/dmesg.boot ]; then
35 839cad07 smos
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
36 e173dd74 Phil Davis
else
37 839cad07 smos
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
38 47eee8fa Scott Ullrich
fi
39 c44417f8 Scott Ullrich
40 b713d790 Scott Ullrich
if [ -z "$AVAILMEM" ]; then
41 3c44c845 Luiz Souza
	MEM=`/sbin/sysctl -q hw.physmem | cut -d':' -f2`
42 51d0f816 Ermal
	AVAILMEM=`/bin/expr $MEM / 1048576`
43 b713d790 Scott Ullrich
fi
44
45 73fa0178 Individual IT Services
46
# Get amount of ram installed on this system
47 3c44c845 Luiz Souza
REALMEM=`/sbin/sysctl -q hw.realmem | /usr/bin/awk '{print $2/1048576}' | /usr/bin/awk -F '.' '{print $1}'`
48 73fa0178 Individual IT Services
export REALMEM
49
export LOWMEM
50
51 5436d37a Renato Botelho
if [  ${REALMEM} -lt $MIN_REALMEM_FOR_OPCACHE ]; then
52 73fa0178 Individual IT Services
	LOWMEM="TRUE"
53 5436d37a Renato Botelho
	echo ">>> Under $MIN_REALMEM_FOR_OPCACHE megabytes of ram detected.  Not enabling opcache"
54
	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
55 73fa0178 Individual IT Services
else
56
57 5436d37a Renato Botelho
	# Calculate opcache memory size according
58 73fa0178 Individual IT Services
	# to detected memory values
59
	if [ "$AVAILMEM" -gt "135" ]; then
60 5436d37a Renato Botelho
		OPCACHEMEMSIZE="10"
61 73fa0178 Individual IT Services
	fi
62
	if [ "$AVAILMEM" -gt "256" ]; then
63 5436d37a Renato Botelho
		OPCACHEMEMSIZE="20"
64 73fa0178 Individual IT Services
	fi
65
	if [ "$AVAILMEM" -gt "384" ]; then
66 5436d37a Renato Botelho
		OPCACHEMEMSIZE="25"
67 73fa0178 Individual IT Services
	fi
68
	if [ "$AVAILMEM" -gt "512" ]; then
69 5436d37a Renato Botelho
		OPCACHEMEMSIZE="30"
70 73fa0178 Individual IT Services
	fi
71
	if [ "$AVAILMEM" -gt "784" ]; then
72 5436d37a Renato Botelho
		OPCACHEMEMSIZE="50"
73 73fa0178 Individual IT Services
	fi
74 2b11ff4d Scott Ullrich
fi
75 40e46009 Scott Ullrich
76 31c96a14 Scott Ullrich
# Set upload directory
77 dc61252a Renato Botelho
UPLOADTMPDIR="/tmp"
78 31c96a14 Scott Ullrich
79 e173dd74 Phil Davis
# Define php modules.  Do not add .so, it will
80 de96a790 Scott Ullrich
# be done automatically by the script below.
81 a4fc6ec7 Ermal
PHPMODULES="standard"
82 c25197ba smos
# Config read/write
83
PHPMODULES="$PHPMODULES xml libxml dom"
84 e115bd22 Renato Botelho
PHPMODULES="$PHPMODULES SimpleXML xmlreader xmlwriter"
85 be1db1d3 Scott Ullrich
# Downloading via HTTP/FTP (pkg mgr, etc)
86 5556f3a1 Ermal
PHPMODULES="$PHPMODULES curl date"
87 e173dd74 Phil Davis
# Internationalization
88 5556f3a1 Ermal
PHPMODULES="$PHPMODULES gettext"
89 be1db1d3 Scott Ullrich
# User manager
90 5556f3a1 Ermal
PHPMODULES="$PHPMODULES ldap openssl pcntl"
91 d9867431 jim-p
PHPMODULES="$PHPMODULES hash"
92 b3765f4c Roberto Nunnari
PHPMODULES="$PHPMODULES mcrypt"
93 be1db1d3 Scott Ullrich
# Regexs, PERL style!
94 5556f3a1 Ermal
PHPMODULES="$PHPMODULES pcre"
95 be1db1d3 Scott Ullrich
# The mighty posix!
96 5556f3a1 Ermal
PHPMODULES="$PHPMODULES posix"
97
PHPMODULES="$PHPMODULES readline"
98 be1db1d3 Scott Ullrich
# Login sessions
99 5556f3a1 Ermal
PHPMODULES="$PHPMODULES session"
100 fca48a65 Scott Ullrich
# Firewall rules edit
101 5556f3a1 Ermal
PHPMODULES="$PHPMODULES ctype"
102 16058a05 Scott Ullrich
# firewall_rules_edit.php
103 5556f3a1 Ermal
PHPMODULES="$PHPMODULES mbstring"
104
# Synchronization primitives
105
PHPMODULES="$PHPMODULES shmop"
106 be1db1d3 Scott Ullrich
# Page compression
107 5556f3a1 Ermal
PHPMODULES="$PHPMODULES zlib"
108
# SQLlite & Database
109
PHPMODULES="$PHPMODULES spl"
110 e115bd22 Renato Botelho
PHPMODULES="$PHPMODULES PDO"
111 6f657dfd Renato Botelho
PHPMODULES="$PHPMODULES sqlite3"
112 04747c75 Warren Baker
# RADIUS
113
PHPMODULES="$PHPMODULES radius"
114 e929c925 Scott Ullrich
# ZeroMQ
115 5556f3a1 Ermal
PHPMODULES="$PHPMODULES zmq"
116
# pfSense extensions
117
PHPMODULES="$PHPMODULES pfSense"
118 a1f77238 Darren Embry
# json
119
PHPMODULES="$PHPMODULES json"
120 c1993935 jim-p
# bcmath
121
PHPMODULES="$PHPMODULES bcmath"
122 c28da0a7 Matt Smith
# filter
123
PHPMODULES="$PHPMODULES filter"
124 475f0b6d Renato Botelho
# rrd
125
PHPMODULES="$PHPMODULES rrd"
126 e83dca8c Scott Ullrich
127 aee36a29 Renato Botelho
PHP_ZEND_MODULES=""
128 8ef700da Scott Ullrich
129 80d887d1 Scott Ullrich
# Modules previously included.
130 fcdf9492 Scott Ullrich
# can be turned on by touching
131 80d887d1 Scott Ullrich
# /etc/php_dynamodules/$modulename
132
#	sysvmsg \
133
#	sysvsem \
134
#	sysvshm \
135
#	bcmath \
136
#	tokenizer \
137
#	uploadprogress \
138
#	sockets \
139
#	Reflection \
140
#	mysql \
141
#	bz2	\
142
143 5556f3a1 Ermal
# Clear the .ini file to make sure we are clean
144 69b27c16 Scott Ullrich
if [ -f /usr/local/etc/php.ini ]; then
145 51d0f816 Ermal
	/bin/rm /usr/local/etc/php.ini
146 69b27c16 Scott Ullrich
fi
147 cb7d18d5 Renato Botelho
LOADED_MODULES=`/usr/local/bin/php-cgi -m | /usr/bin/grep -v "\["`
148 e83dca8c Scott Ullrich
149 a5c36eb2 Renato Botelho
unset TIMEZONE
150 339b8893 Renato Botelho
# Fetch the timezone from /var/db/zoneinfo if present
151
if [ -f /var/db/zoneinfo ]; then
152
	TIMEZONE=$(cat /var/db/zoneinfo)
153 a5c36eb2 Renato Botelho
fi
154
155
if [ -z "${TIMEZONE}" ]; then
156
	# Second option is from config.xml
157
	TIMEZONE=$(/usr/local/sbin/read_xml_tag.sh string system/timezone)
158
fi
159
160
if [ -z "${TIMEZONE}" ]; then
161 e4121dde Renato Botelho
	# Last option, use default value from $g or Etc/UTC
162
	TIMEZONE=$(/usr/local/sbin/read_global_var default_timezone "Etc/UTC")
163 a5c36eb2 Renato Botelho
fi
164
165 45c4bc38 Renato Botelho
if echo "${VERSION}" | grep -q RELEASE; then
166
	error_reporting="error_reporting = E_ERROR | E_PARSE"
167
else
168
	error_reporting=""
169
fi
170
171 5556f3a1 Ermal
# Get a loaded module list in the stock php
172 2ed3203c Scott Ullrich
# Populate a dummy php.ini to avoid
173
# the file being clobbered and the firewall
174
# not being able to boot back up.
175 3646fbcb Renato Botelho
/bin/cat >/usr/local/etc/php.ini <<EOF
176 4b29393a Scott Ullrich
; File generated from /etc/rc.php_ini_setup
177 40e46009 Scott Ullrich
output_buffering = "0"
178
expose_php = Off
179
implicit_flush = true
180
magic_quotes_gpc = Off
181 9d0be827 smos
max_execution_time = 900
182 062a5434 Chris Buechler
request_terminate_timeout = 900
183 7e824233 smos
max_input_time = 1800
184 e56374a8 NewEraCracker
max_input_vars = 5000
185 40e46009 Scott Ullrich
register_argc_argv = On
186 aa205c3b Ermal
register_long_arrays = Off
187 362ec35d Ermal
variables_order = "GPCS"
188 40e46009 Scott Ullrich
file_uploads = On
189 31c96a14 Scott Ullrich
upload_tmp_dir = ${UPLOADTMPDIR}
190 96325dba Warren Baker
upload_max_filesize = 200M
191
post_max_size = 200M
192 40e46009 Scott Ullrich
html_errors = Off
193 f4015bd7 Scott Ullrich
zlib.output_compression = Off
194 40e46009 Scott Ullrich
zlib.output_compression_level = 1
195 981d6364 jim-p
include_path = ".:/etc/inc:/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/"
196 8919256f Scott Ullrich
display_startup_errors=on
197
display_errors=on
198 baa2dba2 Scott Ullrich
log_errors=on
199
error_log=/tmp/PHP_errors.log
200 0804f515 Scott Ullrich
extension_dir=${EXTENSIONSDIR}
201 9d0be827 smos
date.timezone="${TIMEZONE}"
202 3e582e4f NewEraCracker
session.hash_bits_per_character = 5
203
session.hash_function = 1
204 45c4bc38 Renato Botelho
${error_reporting}
205 40e46009 Scott Ullrich
206 4b29393a Scott Ullrich
; Extensions
207 a8e61346 Ermal
208 40e46009 Scott Ullrich
EOF
209
210 e83dca8c Scott Ullrich
# Loop through and generate modules to load.
211
# Take into account modules built into php.
212
for EXT in $PHPMODULES; do
213
	SHOULDADD="true"
214 de96a790 Scott Ullrich
	# Check to see if module is compiled into php statically
215 e83dca8c Scott Ullrich
	for LM in $LOADED_MODULES; do
216
		if [ "$EXT" = "$LM" ]; then
217
			SHOULDADD="false"
218
		fi
219
	done
220
	if [ "$SHOULDADD" = "true" ]; then
221 de96a790 Scott Ullrich
		# Ensure extension exists before adding.
222 69b27c16 Scott Ullrich
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
223 3646fbcb Renato Botelho
			echo "extension=${EXT}.so" >> /usr/local/etc/php.ini
224 0804f515 Scott Ullrich
		fi
225 e83dca8c Scott Ullrich
	fi
226
done
227
228 8ef700da Scott Ullrich
# Zend modules
229
for EXT in $PHP_ZEND_MODULES; do
230
	# Ensure extension exists before adding.
231 aee36a29 Renato Botelho
	if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
232 3646fbcb Renato Botelho
		echo "zend_extension=${EXT}.so" >> /usr/local/etc/php.ini
233 8ef700da Scott Ullrich
	fi
234
done
235
236 73fa0178 Individual IT Services
if [ "$LOWMEM" != "TRUE" ]; then
237 40e46009 Scott Ullrich
238 3646fbcb Renato Botelho
	/bin/cat >>/usr/local/etc/php.ini <<EOF
239 e83dca8c Scott Ullrich
240 5436d37a Renato Botelho
; opcache Settings
241
opcache.enabled="1"
242
opcache.enable_cli="0"
243
opcache.memory_consumption="${OPCACHEMEMSIZE}"
244 40e46009 Scott Ullrich
245 a5c53d26 Renato Botelho
EOF
246
else
247 3646fbcb Renato Botelho
	/bin/cat >>/usr/local/etc/php.ini <<EOF
248 a5c53d26 Renato Botelho
; opcache Settings
249
opcache.enabled="0"
250 5556f3a1 Ermal
EOF
251
fi
252
253 6d7ee1ab Ermal
PHPFPMMAX=3
254 2c131b10 marjohn56
PHPFPMIDLE=30
255
PHPFPMSTART=1
256
PHPFPMSPARE=2
257
PHPFPMREQ=500
258 7b03748b Ermal
if [ $REALMEM -lt 250 ]; then
259 6d7ee1ab Ermal
	PHPFPMMAX=2
260 2c131b10 marjohn56
       PHPFPMIDLE=5
261
       PHPFPMSTART=1
262
       PHPFPMSPARE=1
263
       PHPFPMREQ=500
264 4aea91d8 Ermal
elif [ ${REALMEM} -gt 1000 ]; then
265 2c131b10 marjohn56
       PHPFPMMAX=8
266
       PHPFPMIDLE=3600
267
       PHPFPMSTART=2
268
       PHPFPMSPARE=7
269 179377b0 robjarsen
       PHPFPMREQ=5000
270 4aea91d8 Ermal
fi
271
272
/bin/cat > /usr/local/lib/php-fpm.conf <<EOF
273
274
[global]
275
pid = run/php-fpm.pid
276
error_log=syslog
277
syslog.facility = daemon
278 9e0fb701 Ermal
syslog.ident = system
279 3ffae79b Ermal
log_level = error
280 4aea91d8 Ermal
daemonize = yes
281
events.mechanism = kqueue
282
process.max = ${PHPFPMMAX}
283
284 40880eec Renato Botelho
[nginx]
285 4aea91d8 Ermal
user = root
286
group = wheel
287
;mode = 0600
288
289
listen = /var/run/php-fpm.socket
290
listen.owner = root
291
listen.group = wheel
292
listen.mode = 0600
293
294
security.limit_extensions =
295
296 5293c5c7 Warren Baker
; Pass environment variables
297
env[PATH] = /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
298 75b8eb83 Renato Botelho
env[LOGNAME] = root
299 5293c5c7 Warren Baker
300 4aea91d8 Ermal
EOF
301
302 5be2085a Ermal
if [ $REALMEM -lt 350 ]; then
303 4aea91d8 Ermal
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
304
305
pm = ondemand
306 2c131b10 marjohn56
pm.process_idle_timeout = $PHPFPMIDLE
307 6d7ee1ab Ermal
pm.max_children = $PHPFPMMAX
308 2c131b10 marjohn56
pm.max_requests = $PHPFPMREQ
309 4aea91d8 Ermal
EOF
310
311
elif [ $REALMEM -gt 1000 ]; then
312
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
313
314
pm = dynamic
315 2c131b10 marjohn56
pm.process_idle_timeout = $PHPFPMIDLE
316 6d7ee1ab Ermal
pm.max_children = $PHPFPMMAX
317 2c131b10 marjohn56
pm.start_servers = $PHPFPMSTART
318
pm.max_requests = $PHPFPMREQ
319 4aea91d8 Ermal
pm.min_spare_servers=1
320 2c131b10 marjohn56
pm.max_spare_servers= $PHPFPMSPARE
321
322 4aea91d8 Ermal
EOF
323
else
324
325
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
326
327
pm = static
328 6d7ee1ab Ermal
pm.max_children = $PHPFPMMAX
329 2c131b10 marjohn56
pm.max_requests = $PHPFPMREQ
330 4aea91d8 Ermal
EOF
331
332
fi
333
334 418fdfb3 PiBa-NL
# Add status url for php-fpm this will only be made available from localhost through nginx 'allow 127.0.0.1'
335
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
336
pm.status_path = /status
337
338
EOF
339
340 e1fda0c0 Scott Ullrich
# Remove old log file if it exists.
341
if [ -f /var/run/php_modules_load_errors.txt ]; then
342 51d0f816 Ermal
	/bin/rm /var/run/php_modules_load_errors.txt
343 e173dd74 Phil Davis
fi
344 e1fda0c0 Scott Ullrich
345 7030262c Scott Ullrich
for EXT in $PHPMODULES; do
346 51d0f816 Ermal
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]'`"
347 7030262c Scott Ullrich
done
348
349 e1fda0c0 Scott Ullrich
# Check loaded modules and remove anything that did not load correctly
350 cb7d18d5 Renato Botelho
LOADED_MODULES=`/usr/local/bin/php-cgi -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\["`
351 7030262c Scott Ullrich
for EXT in $PHPMODULESLC; do
352 e1fda0c0 Scott Ullrich
	SHOULDREMOVE="true"
353
	for LM in $LOADED_MODULES; do
354
		if [ "$EXT" = "$LM" ]; then
355
			SHOULDREMOVE="false"
356 14dd1631 Renato Botelho
			break
357 e173dd74 Phil Davis
		fi
358 e1fda0c0 Scott Ullrich
	done
359 1e86e897 Scott Ullrich
	# Handle low memory situations
360 8ee1dc80 Scott Ullrich
	if [ "$LOWMEM" = "TRUE" ]; then
361 5436d37a Renato Botelho
		if [ "$EXT" = "opcache" ]; then
362 8ee1dc80 Scott Ullrich
			SHOULDREMOVE="true"
363
		fi
364
		if [ "$EXT" = "xcache" ]; then
365
			SHOULDREMOVE="true"
366
		fi
367
	fi
368 e1fda0c0 Scott Ullrich
	if [ "$SHOULDREMOVE" = "true" ]; then
369
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
370
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
371 3646fbcb Renato Botelho
			/bin/cat /usr/local/etc/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
372
			/bin/rm -f /usr/local/etc/php.ini
373
			/bin/mv /tmp/php.ini /usr/local/etc/php.ini
374 e1fda0c0 Scott Ullrich
		fi
375
	fi
376
done