Projet

Général

Profil

Télécharger (11 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc.php_ini_setup @ c28da0a7

1 40e46009 Scott Ullrich
#!/bin/sh
2 de96a790 Scott Ullrich
#
3
#	rc.php_ini_setup
4 1e86e897 Scott Ullrich
#	Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
5 de96a790 Scott Ullrich
#	All rights reserved.
6
#
7
#	Redistribution and use in source and binary forms, with or without
8
#	modification, are permitted provided that the following conditions are met:
9
#
10
#	1. Redistributions of source code must retain the above copyright notice,
11
#	   this list of conditions and the following disclaimer.
12
#
13
#	2. Redistributions in binary form must reproduce the above copyright
14
#	   notice, this list of conditions and the following disclaimer in the
15
#	   documentation and/or other materials provided with the distribution.
16
#
17
#	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
#	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
#	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
#	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
#	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
#	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
#	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
#	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
#	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
#	POSSIBILITY OF SUCH DAMAGE.
27 40e46009 Scott Ullrich
28
# Set our operating platform
29 51d0f816 Ermal
PLATFORM=`/bin/cat /etc/platform`
30 73fa0178 Individual IT Services
MIN_REALMEM_FOR_APC=512
31 c44417f8 Scott Ullrich
32 01f4a81d Renato Botelho
if [ -d /usr/local/lib/php/20121212 ]; then
33
	EXTENSIONSDIR="/usr/local/lib/php/20121212/"
34
elif [ -d /usr/local/lib/php/20090626 ]; then
35 79454450 Scott Ullrich
	EXTENSIONSDIR="/usr/local/lib/php/20090626/"
36
else
37
	EXTENSIONSDIR="/usr/local/lib/php/20060613/"
38
fi
39
40 0d60f50a Seth Mos
# Grab amount of memory that is detected
41 47eee8fa Scott Ullrich
if [ -f /var/log/dmesg.boot ]; then
42 839cad07 smos
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
43 47eee8fa Scott Ullrich
else 
44 839cad07 smos
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
45 47eee8fa Scott Ullrich
fi
46 c44417f8 Scott Ullrich
47 b713d790 Scott Ullrich
if [ -z "$AVAILMEM" ]; then
48 51d0f816 Ermal
	MEM=`/sbin/sysctl hw.physmem | cut -d':' -f2`
49
	AVAILMEM=`/bin/expr $MEM / 1048576`
50 b713d790 Scott Ullrich
fi
51
52 73fa0178 Individual IT Services
53
# Get amount of ram installed on this system
54
REALMEM=`/sbin/sysctl hw.realmem | /usr/bin/awk '{print $2/1048576}' | /usr/bin/awk -F '.' '{print $1}'`
55
export REALMEM
56
export LOWMEM
57
58 4aea91d8 Ermal
if [  ${REALMEM} -lt $MIN_REALMEM_FOR_APC ]; then
59 73fa0178 Individual IT Services
	LOWMEM="TRUE"
60 4831f5df Renato Botelho
	echo ">>> Under $MIN_REALMEM_FOR_APC megabytes of ram detected.  Not enabling APC."
61
	echo ">>> Under $MIN_REALMEM_FOR_APC megabytes of ram detected.  Not enabling APC." | /usr/bin/logger -p daemon.info -i -t rc.php_ini_setup
62 73fa0178 Individual IT Services
else
63
64
	# Calculate APC SHM size according 
65
	# to detected memory values
66
	if [ "$AVAILMEM" -gt "135" ]; then
67
		APCSHMEMSIZE="10M"
68
	fi
69
	if [ "$AVAILMEM" -gt "256" ]; then
70
		APCSHMEMSIZE="20M"
71
	fi
72
	if [ "$AVAILMEM" -gt "384" ]; then
73
		APCSHMEMSIZE="25M"
74
	fi
75
	if [ "$AVAILMEM" -gt "512" ]; then
76
		APCSHMEMSIZE="30M"
77
	fi
78
	if [ "$AVAILMEM" -gt "784" ]; then
79
		APCSHMEMSIZE="50M"
80
	fi
81 2b11ff4d Scott Ullrich
fi
82 40e46009 Scott Ullrich
83 31c96a14 Scott Ullrich
# Set upload directory
84 e61f548f Ermal
if [ "$PLATFORM" = "nanobsd" ]; then
85 7ff663d3 Warren Baker
	UPLOADTMPDIR=`/usr/bin/grep upload_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
86 31c96a14 Scott Ullrich
else 
87
	UPLOADTMPDIR="/tmp"
88
fi
89
90 de96a790 Scott Ullrich
# Define php modules.  Do not add .so, it will  
91
# be done automatically by the script below.
92 a4fc6ec7 Ermal
PHPMODULES="standard"
93 73fa0178 Individual IT Services
if [ "$LOWMEM" != "TRUE" ]; then
94 a4fc6ec7 Ermal
	PHPMODULES="$PHPMODULES apc"
95
fi
96 c25197ba smos
# Config read/write
97
PHPMODULES="$PHPMODULES xml libxml dom"
98
PHPMODULES="$PHPMODULES simplexml xmlreader xmlwriter"
99 be1db1d3 Scott Ullrich
# Downloading via HTTP/FTP (pkg mgr, etc)
100 5556f3a1 Ermal
PHPMODULES="$PHPMODULES curl date"
101 be1db1d3 Scott Ullrich
# Internationalization 
102 5556f3a1 Ermal
PHPMODULES="$PHPMODULES gettext"
103 be1db1d3 Scott Ullrich
# User manager
104 5556f3a1 Ermal
PHPMODULES="$PHPMODULES ldap openssl pcntl"
105 d9867431 jim-p
PHPMODULES="$PHPMODULES hash"
106 b3765f4c Roberto Nunnari
PHPMODULES="$PHPMODULES mcrypt"
107 be1db1d3 Scott Ullrich
# Regexs, PERL style!
108 5556f3a1 Ermal
PHPMODULES="$PHPMODULES pcre"
109 be1db1d3 Scott Ullrich
# The mighty posix!
110 5556f3a1 Ermal
PHPMODULES="$PHPMODULES posix"
111
PHPMODULES="$PHPMODULES readline"
112 be1db1d3 Scott Ullrich
# Login sessions
113 5556f3a1 Ermal
PHPMODULES="$PHPMODULES session"
114 be1db1d3 Scott Ullrich
# Extra sanity seatbelts
115 c25197ba smos
PHPMODULES="$PHPMODULES suhosin"
116 fca48a65 Scott Ullrich
# Firewall rules edit
117 5556f3a1 Ermal
PHPMODULES="$PHPMODULES ctype"
118 16058a05 Scott Ullrich
# firewall_rules_edit.php
119 5556f3a1 Ermal
PHPMODULES="$PHPMODULES mbstring"
120
# Synchronization primitives
121
PHPMODULES="$PHPMODULES shmop"
122 be1db1d3 Scott Ullrich
# Page compression
123 5556f3a1 Ermal
PHPMODULES="$PHPMODULES zlib"
124
# SQLlite & Database
125
PHPMODULES="$PHPMODULES spl"
126
PHPMODULES="$PHPMODULES pdo"
127 6f657dfd Renato Botelho
PHPMODULES="$PHPMODULES sqlite3"
128 04747c75 Warren Baker
# RADIUS
129
PHPMODULES="$PHPMODULES radius"
130 e929c925 Scott Ullrich
# ZeroMQ
131 5556f3a1 Ermal
PHPMODULES="$PHPMODULES zmq"
132 c88ff708 Scott Ullrich
# SSH2
133
PHPMODULES="$PHPMODULES ssh2"
134 5556f3a1 Ermal
# pfSense extensions
135
PHPMODULES="$PHPMODULES pfSense"
136 a1f77238 Darren Embry
# json
137
PHPMODULES="$PHPMODULES json"
138 c1993935 jim-p
# bcmath
139
PHPMODULES="$PHPMODULES bcmath"
140 c28da0a7 Matt Smith
# filter
141
PHPMODULES="$PHPMODULES filter"
142 e83dca8c Scott Ullrich
143 277ee858 lgcosta
PHP_ZEND_MODULES="ioncube_loader"
144
PHP_ZEND_MODULES_TS="ioncube_loader_ts"
145 8ef700da Scott Ullrich
146 80d887d1 Scott Ullrich
# Modules previously included.
147 fcdf9492 Scott Ullrich
# can be turned on by touching
148 80d887d1 Scott Ullrich
# /etc/php_dynamodules/$modulename
149
#	sysvmsg \
150
#	sysvsem \
151
#	sysvshm \
152
#	bcmath \
153
#	tokenizer \
154
#	uploadprogress \
155
#	sockets \
156
#	Reflection \
157
#	mysql \
158
#	bz2	\
159
160 5556f3a1 Ermal
# Clear the .ini file to make sure we are clean
161 69b27c16 Scott Ullrich
if [ -f /usr/local/etc/php.ini ]; then
162 51d0f816 Ermal
	/bin/rm /usr/local/etc/php.ini
163 69b27c16 Scott Ullrich
fi
164
if [ -f /usr/local/lib/php.ini ]; then
165 51d0f816 Ermal
	/bin/rm /usr/local/lib/php.ini
166 69b27c16 Scott Ullrich
fi
167 51d0f816 Ermal
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/grep -v "\["`
168 e83dca8c Scott Ullrich
169 9d0be827 smos
# Fetch the timezone from the XML and set it here. We set it later too in the running scripts
170
TIMEZONE=`cat /conf/config.xml | egrep -E '<timezone>(.*?)</timezone>' | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
171
172 5556f3a1 Ermal
# Get a loaded module list in the stock php
173 2ed3203c Scott Ullrich
# Populate a dummy php.ini to avoid
174
# the file being clobbered and the firewall
175
# not being able to boot back up.
176 51d0f816 Ermal
/bin/cat >/usr/local/lib/php.ini <<EOF
177 4b29393a Scott Ullrich
; File generated from /etc/rc.php_ini_setup
178 40e46009 Scott Ullrich
output_buffering = "0"
179
expose_php = Off
180
implicit_flush = true
181
magic_quotes_gpc = Off
182 9d0be827 smos
max_execution_time = 900
183 7e824233 smos
max_input_time = 1800
184 40e46009 Scott Ullrich
register_argc_argv = On
185 aa205c3b Ermal
register_long_arrays = Off
186 362ec35d Ermal
variables_order = "GPCS"
187 40e46009 Scott Ullrich
file_uploads = On
188 31c96a14 Scott Ullrich
upload_tmp_dir = ${UPLOADTMPDIR}
189 96325dba Warren Baker
upload_max_filesize = 200M
190
post_max_size = 200M
191 40e46009 Scott Ullrich
html_errors = Off
192 f4015bd7 Scott Ullrich
zlib.output_compression = Off
193 40e46009 Scott Ullrich
zlib.output_compression_level = 1
194
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
195 8919256f Scott Ullrich
display_startup_errors=on
196
display_errors=on
197 baa2dba2 Scott Ullrich
log_errors=on
198
error_log=/tmp/PHP_errors.log
199 0804f515 Scott Ullrich
extension_dir=${EXTENSIONSDIR}
200 9d0be827 smos
date.timezone="${TIMEZONE}"
201 40e46009 Scott Ullrich
202 4b29393a Scott Ullrich
; Extensions
203 a8e61346 Ermal
204 40e46009 Scott Ullrich
EOF
205
206 5556f3a1 Ermal
# Copy php.ini file to etc/ too (cli)
207 51d0f816 Ermal
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
208 5556f3a1 Ermal
209 7f16265a Scott Ullrich
# Ensure directory exists
210
if [ ! -d /etc/php_dynamodules ]; then
211 51d0f816 Ermal
	/bin/mkdir /etc/php_dynamodules
212 7f16265a Scott Ullrich
fi
213 5b9afe1e Scott Ullrich
if [ ! -d /etc/php_dynamodules_zend ]; then
214
	/bin/mkdir /etc/php_dynamodules_zend
215
fi
216
if [ ! -d /etc/php_dynamodules_zend_ts ]; then
217
	/bin/mkdir /etc/php_dynamodules_zend_ts
218
fi
219 7f16265a Scott Ullrich
220
# Read in dynamodules
221 c44417f8 Scott Ullrich
if [ -d /etc/php_dynamodules ]; then
222 fd3e19f3 Scott Ullrich
	DYNA_MODULES=`/bin/ls -Utr /etc/php_dynamodules/`
223 c44417f8 Scott Ullrich
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
224
fi
225
226 8ef700da Scott Ullrich
# Read in zend modules
227
if [ -d /etc/php_dynamodules_zend ]; then
228 f81cbdad Scott Ullrich
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend/`
229 8ef700da Scott Ullrich
	PHP_ZEND_MODULES="$PHP_ZEND_MODULES $DYNA_MODULES"
230
fi
231
232
# Read in zend threaded modules
233
if [ -d /etc/php_dynamodules_zend_ts ]; then
234 f81cbdad Scott Ullrich
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend_ts/`
235 14033103 Scott Ullrich
	PHP_ZEND_MODULES_TS="$PHP_ZEND_MODULES_TS $DYNA_MODULES"
236 8ef700da Scott Ullrich
fi
237
238 e83dca8c Scott Ullrich
# Loop through and generate modules to load.
239
# Take into account modules built into php.
240
for EXT in $PHPMODULES; do
241
	SHOULDADD="true"
242 de96a790 Scott Ullrich
	# Check to see if module is compiled into php statically
243 e83dca8c Scott Ullrich
	for LM in $LOADED_MODULES; do
244
		if [ "$EXT" = "$LM" ]; then
245
			SHOULDADD="false"
246
		fi
247
	done
248
	if [ "$SHOULDADD" = "true" ]; then
249 de96a790 Scott Ullrich
		# Ensure extension exists before adding.
250 69b27c16 Scott Ullrich
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
251 0804f515 Scott Ullrich
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
252
		fi
253 e83dca8c Scott Ullrich
	fi
254
done
255
256 8ef700da Scott Ullrich
# Zend modules
257
for EXT in $PHP_ZEND_MODULES; do
258
	# Ensure extension exists before adding.
259 5c52cd56 lgcosta
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
260
		echo "zend_extension=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
261 8ef700da Scott Ullrich
	fi
262
done
263
264
# Zend threaded modules
265
for EXT in $PHP_ZEND_MODULES_TS; do
266
	# Ensure extension exists before adding.
267 5c52cd56 lgcosta
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
268
		echo "zend_extension_ts=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
269 8ef700da Scott Ullrich
	fi
270
done
271
272 73fa0178 Individual IT Services
273
if [ "$LOWMEM" != "TRUE" ]; then
274 40e46009 Scott Ullrich
275 51d0f816 Ermal
	/bin/cat >>/usr/local/lib/php.ini <<EOF
276 e83dca8c Scott Ullrich
277 4b29393a Scott Ullrich
; APC Settings
278 40e46009 Scott Ullrich
apc.enabled="1"
279 59218e22 Scott Ullrich
apc.enable_cli="0"
280 de96a790 Scott Ullrich
apc.shm_size="${APCSHMEMSIZE}"
281 40e46009 Scott Ullrich
282 5556f3a1 Ermal
EOF
283
fi
284
285 51d0f816 Ermal
	/bin/cat >>/usr/local/lib/php.ini <<EOF
286 5556f3a1 Ermal
287 a8e61346 Ermal
[suhosin]
288
suhosin.get.max_array_depth = 5000
289
suhosin.get.max_array_index_length = 256
290
suhosin.get.max_vars = 5000
291 4f1bace5 Ermal
suhosin.get.max_value_length = 500000
292 a8e61346 Ermal
suhosin.post.max_array_depth = 5000
293
suhosin.post.max_array_index_length = 256
294
suhosin.post.max_vars = 5000
295 4f1bace5 Ermal
suhosin.post.max_value_length = 500000
296 a8e61346 Ermal
suhosin.request.max_array_depth = 5000
297
suhosin.request.max_array_index_length = 256
298
suhosin.request.max_vars = 5000
299 4f1bace5 Ermal
suhosin.request.max_value_length = 500000
300 b9bc333b Scott Ullrich
suhosin.memory_limit = 512435456
301 a8e61346 Ermal
302 40e46009 Scott Ullrich
EOF
303
304
305 6d7ee1ab Ermal
PHPFPMMAX=3
306 7b03748b Ermal
if [ $REALMEM -lt 250 ]; then
307 6d7ee1ab Ermal
	PHPFPMMAX=2
308 4aea91d8 Ermal
elif [ ${REALMEM} -gt 1000 ]; then
309
	PHPFPMMAX=4
310
fi
311
312
/bin/cat > /usr/local/lib/php-fpm.conf <<EOF
313
314
[global]
315
pid = run/php-fpm.pid
316
error_log=syslog
317
syslog.facility = daemon
318 9e0fb701 Ermal
syslog.ident = system
319 3ffae79b Ermal
log_level = error
320 4aea91d8 Ermal
daemonize = yes
321
events.mechanism = kqueue
322
process.max = ${PHPFPMMAX}
323
324
[lighty]
325
user = root
326
group = wheel
327
;mode = 0600
328
329
listen = /var/run/php-fpm.socket
330
listen.owner = root
331
listen.group = wheel
332
listen.mode = 0600
333
334
security.limit_extensions =
335
336 5293c5c7 Warren Baker
; Pass environment variables
337
env[PATH] = /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
338 75b8eb83 Renato Botelho
env[LOGNAME] = root
339 5293c5c7 Warren Baker
340 4aea91d8 Ermal
EOF
341
342 5be2085a Ermal
if [ $REALMEM -lt 350 ]; then
343 4aea91d8 Ermal
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
344
345
pm = ondemand
346
pm.process_idle_timeout = 5
347 6d7ee1ab Ermal
pm.max_children = $PHPFPMMAX
348 4aea91d8 Ermal
pm.max_requests = 500
349
350
EOF
351
352
elif [ $REALMEM -gt 1000 ]; then
353
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
354
355
pm = dynamic
356
pm.process_idle_timeout = 5
357 6d7ee1ab Ermal
pm.max_children = $PHPFPMMAX
358 4aea91d8 Ermal
pm.start_servers = 1
359
pm.max_requests = 500
360
pm.min_spare_servers=1
361
pm.max_spare_servers=1
362
363
EOF
364
else
365
366
	/bin/cat >> /usr/local/lib/php-fpm.conf <<EOF
367
368
pm = static
369 6d7ee1ab Ermal
pm.max_children = $PHPFPMMAX
370 4aea91d8 Ermal
pm.max_requests = 500
371
372
EOF
373
374
fi
375
376 de96a790 Scott Ullrich
# Copy php.ini file to etc/ too (cli)
377 51d0f816 Ermal
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
378 e1fda0c0 Scott Ullrich
379
# Remove old log file if it exists.
380
if [ -f /var/run/php_modules_load_errors.txt ]; then
381 51d0f816 Ermal
	/bin/rm /var/run/php_modules_load_errors.txt
382 e1fda0c0 Scott Ullrich
fi 
383
384 7030262c Scott Ullrich
for EXT in $PHPMODULES; do
385 51d0f816 Ermal
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]'`"
386 7030262c Scott Ullrich
done
387
388 e1fda0c0 Scott Ullrich
# Check loaded modules and remove anything that did not load correctly
389 51d0f816 Ermal
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\["`
390 7030262c Scott Ullrich
for EXT in $PHPMODULESLC; do
391 e1fda0c0 Scott Ullrich
	SHOULDREMOVE="true"
392
	for LM in $LOADED_MODULES; do
393
		if [ "$EXT" = "$LM" ]; then
394
			SHOULDREMOVE="false"
395
		fi		
396
	done
397 1e86e897 Scott Ullrich
	# Handle low memory situations
398 8ee1dc80 Scott Ullrich
	if [ "$LOWMEM" = "TRUE" ]; then
399
		if [ "$EXT" = "apc" ]; then
400
			SHOULDREMOVE="true"
401
		fi
402
		if [ "$EXT" = "xcache" ]; then
403
			SHOULDREMOVE="true"
404
		fi
405
	fi
406 e1fda0c0 Scott Ullrich
	if [ "$SHOULDREMOVE" = "true" ]; then
407
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
408
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
409 51d0f816 Ermal
			/bin/cat /usr/local/lib/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
410
			/bin/rm -f /usr/local/lib/php.ini
411
			/bin/mv /tmp/php.ini /usr/local/lib/php.ini
412 e1fda0c0 Scott Ullrich
		fi
413
	fi
414
done
415
416
# Copy php.ini file to etc/ too (cli)
417 51d0f816 Ermal
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini