Project

General

Profile

Download (7.75 KB) Statistics
| Branch: | Tag: | Revision:
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 80a2fedf Scott Ullrich
if [ -f /usr/local/etc/php.ini ]; then
29
	rm /usr/local/etc/php.ini
30
fi
31
if [ -f /usr/local/lib/php.ini ]; then
32
	rm /usr/local/lib/php.ini
33
fi
34
35 40e46009 Scott Ullrich
# Set our operating platform
36
PLATFORM=`cat /etc/platform`
37 0804f515 Scott Ullrich
EXTENSIONSDIR="/usr/local/lib/php/20060613/"
38 c44417f8 Scott Ullrich
39 0d60f50a Seth Mos
# Grab amount of memory that is detected
40 47eee8fa Scott Ullrich
if [ -f /var/log/dmesg.boot ]; then
41 839cad07 smos
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
42 47eee8fa Scott Ullrich
else 
43 839cad07 smos
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
44 47eee8fa Scott Ullrich
fi
45 c44417f8 Scott Ullrich
46 b713d790 Scott Ullrich
if [ -z "$AVAILMEM" ]; then
47
	MEM=`sysctl hw.physmem | cut -d':' -f2`
48
	AVAILMEM=`expr $MEM / 1048576`
49
fi
50
51 2b11ff4d Scott Ullrich
# Calculate APC SHM size according 
52
# to detected memory values
53 cddedb40 Scott Ullrich
if [ "$AVAILMEM" -lt "65" ]; then
54
	APCSHMEMSIZE="1"
55
fi
56
if [ "$AVAILMEM" -lt "96" ]; then
57 96e04209 Scott Ullrich
	APCSHMEMSIZE="5"
58 cddedb40 Scott Ullrich
fi
59 2b11ff4d Scott Ullrich
if [ "$AVAILMEM" -lt "128" ]; then
60 f82be9e4 Scott Ullrich
	APCSHMEMSIZE="10"
61 2b11ff4d Scott Ullrich
fi
62
if [ "$AVAILMEM" -gt "128" ]; then
63 1e86e897 Scott Ullrich
	APCSHMEMSIZE="15"
64 2b11ff4d Scott Ullrich
fi
65
if [ "$AVAILMEM" -gt "256" ]; then
66 1e86e897 Scott Ullrich
	APCSHMEMSIZE="20"
67 2b11ff4d Scott Ullrich
fi
68
if [ "$AVAILMEM" -gt "384" ]; then
69 1e86e897 Scott Ullrich
	APCSHMEMSIZE="25"
70 2b11ff4d Scott Ullrich
fi
71
if [ "$AVAILMEM" -gt "512" ]; then
72 1e86e897 Scott Ullrich
	APCSHMEMSIZE="30"
73 2b11ff4d Scott Ullrich
fi
74
if [ "$AVAILMEM" -gt "784" ]; then
75 1e86e897 Scott Ullrich
	APCSHMEMSIZE="35"
76 2b11ff4d Scott Ullrich
fi
77 40e46009 Scott Ullrich
78 31c96a14 Scott Ullrich
# Set upload directory
79 dee5d2fb Renato Botelho
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
80 800b73e6 Scott Ullrich
	UPLOADTMPDIR="/root"
81 31c96a14 Scott Ullrich
else 
82
	UPLOADTMPDIR="/tmp"
83
fi
84
85 de96a790 Scott Ullrich
# Define php modules.  Do not add .so, it will  
86
# be done automatically by the script below.
87 0997e8f3 Scott Ullrich
PHPMODULES="apc \
88 be1db1d3 Scott Ullrich
# Downloading via HTTP/FTP (pkg mgr, etc)
89 f1b64d5e Scott Ullrich
	curl \
90
	date \
91 be1db1d3 Scott Ullrich
# Internationalization 
92 f1b64d5e Scott Ullrich
	gettext \
93 be1db1d3 Scott Ullrich
# User manager
94 f1b64d5e Scott Ullrich
	ldap \
95 8a44206b Scott Ullrich
	openssl \
96 f1b64d5e Scott Ullrich
	pcntl \
97 be1db1d3 Scott Ullrich
# Regexs, PERL style!
98 f1b64d5e Scott Ullrich
	pcre \
99 be1db1d3 Scott Ullrich
# The mighty posix!
100 f1b64d5e Scott Ullrich
	posix \
101
	readline \
102 be1db1d3 Scott Ullrich
# Login sessions
103 f1b64d5e Scott Ullrich
	session \
104
	standard \
105 be1db1d3 Scott Ullrich
# Extra sanity seatbelts
106 27798303 Scott Ullrich
	suhosin \
107 7a14caf0 Scott Ullrich
	pfSense \
108 fca48a65 Scott Ullrich
# Firewall rules edit
109
	ctype \
110 be1db1d3 Scott Ullrich
# Config read/write
111 f1b64d5e Scott Ullrich
	xml \
112 caea0c47 Ermal Lu?i
	xmlreader \
113 a669395c Ermal
	xmlwriter \
114 be1db1d3 Scott Ullrich
	libxml \
115 d4ac1b88 Scott Ullrich
# user manager
116
	mhash \
117 16058a05 Scott Ullrich
# firewall_rules_edit.php
118
	mbstring \
119 8eae944e Ermal
	shmop \
120 be1db1d3 Scott Ullrich
# Page compression
121 e929c925 Scott Ullrich
	zlib \
122 bdf6ac75 Scott Ullrich
# SQLlite
123 90108d90 Scott Ullrich
	simplexml \
124 0bf80970 Scott Ullrich
	spl \
125 bdf6ac75 Scott Ullrich
	pdo \
126 52e65de1 Scott Ullrich
	sqlite \
127 e929c925 Scott Ullrich
# ZeroMQ
128
	zmq"
129 e83dca8c Scott Ullrich
130 80d887d1 Scott Ullrich
# Modules previously included.
131 fcdf9492 Scott Ullrich
# can be turned on by touching
132 80d887d1 Scott Ullrich
# /etc/php_dynamodules/$modulename
133
#	sysvmsg \
134
#	sysvsem \
135
#	sysvshm \
136
#	bcmath \
137
#	tokenizer \
138
#	uploadprogress \
139
#	sockets \
140
#	Reflection \
141
#	mysql \
142
#	bz2	\
143
#	json \
144
145 de96a790 Scott Ullrich
# Get a loaded module list in the stock php
146 69b27c16 Scott Ullrich
if [ -f /usr/local/etc/php.ini ]; then
147
	rm /usr/local/etc/php.ini
148
fi
149
if [ -f /usr/local/lib/php.ini ]; then
150
	rm /usr/local/lib/php.ini
151
fi
152
LOADED_MODULES=`php -m | grep -v "\["`
153 e83dca8c Scott Ullrich
154 2ed3203c Scott Ullrich
# Populate a dummy php.ini to avoid
155
# the file being clobbered and the firewall
156
# not being able to boot back up.
157
cat >/usr/local/lib/php.ini <<EOF
158 4b29393a Scott Ullrich
; File generated from /etc/rc.php_ini_setup
159 40e46009 Scott Ullrich
output_buffering = "0"
160
expose_php = Off
161
implicit_flush = true
162
magic_quotes_gpc = Off
163
max_execution_time = 99999999
164
max_input_time = 99999999
165 c720fffc Scott Ullrich
set_time_limit = 0
166 40e46009 Scott Ullrich
register_argc_argv = On
167
file_uploads = On
168 31c96a14 Scott Ullrich
upload_tmp_dir = ${UPLOADTMPDIR}
169 40e46009 Scott Ullrich
upload_max_filesize = 100M
170
post_max_size = 100M
171
html_errors = Off
172 9444761e sullrich
zlib.output_compression = Off
173 40e46009 Scott Ullrich
zlib.output_compression_level = 1
174
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
175 0804f515 Scott Ullrich
extension_dir=${EXTENSIONSDIR}
176 40e46009 Scott Ullrich
177 4b29393a Scott Ullrich
; Extensions
178 a8e61346 Ermal
179 40e46009 Scott Ullrich
EOF
180
181 7f16265a Scott Ullrich
# Ensure directory exists
182
if [ ! -d /etc/php_dynamodules ]; then
183
	mkdir /etc/php_dynamodules
184
fi
185
186
# Read in dynamodules
187 c44417f8 Scott Ullrich
if [ -d /etc/php_dynamodules ]; then
188
	DYNA_MODULES=`ls /etc/php_dynamodules/`
189
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
190
fi
191
192 e83dca8c Scott Ullrich
# Loop through and generate modules to load.
193
# Take into account modules built into php.
194
for EXT in $PHPMODULES; do
195
	SHOULDADD="true"
196 de96a790 Scott Ullrich
	# Check to see if module is compiled into php statically
197 e83dca8c Scott Ullrich
	for LM in $LOADED_MODULES; do
198
		if [ "$EXT" = "$LM" ]; then
199
			SHOULDADD="false"
200
		fi
201
	done
202
	if [ "$SHOULDADD" = "true" ]; then
203 de96a790 Scott Ullrich
		# Ensure extension exists before adding.
204 69b27c16 Scott Ullrich
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
205 0804f515 Scott Ullrich
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
206
		fi
207 e83dca8c Scott Ullrich
	fi
208
done
209
210 de96a790 Scott Ullrich
# Get amount of ram installed on this system
211 40e46009 Scott Ullrich
RAM=`sysctl hw.realmem | awk '{print $2/1000000}' | awk -F '.' '{print $1}'`
212
export RAM
213 8ee1dc80 Scott Ullrich
export LOWMEM
214
if [ "$RAM" -lt "97" ]; then
215
	LOWMEM="TRUE"
216 cddedb40 Scott Ullrich
	cat >>/usr/local/lib/php.ini <<EOF
217
218
[suhosin]
219
suhosin.get.max_array_depth = 5000
220
suhosin.get.max_array_index_length = 256
221
suhosin.get.max_vars = 5000
222 4f1bace5 Ermal
suhosin.get.max_value_length = 500000
223 cddedb40 Scott Ullrich
suhosin.post.max_array_depth = 5000
224
suhosin.post.max_array_index_length = 256
225
suhosin.post.max_vars = 5000
226 4f1bace5 Ermal
suhosin.post.max_value_length = 500000
227 cddedb40 Scott Ullrich
suhosin.request.max_array_depth = 5000
228
suhosin.request.max_array_index_length = 256
229
suhosin.request.max_vars = 5000
230 4f1bace5 Ermal
suhosin.request.max_value_length = 500000
231 cddedb40 Scott Ullrich
232
EOF
233
234
fi
235 4f1bace5 Ermal
if [  "$RAM" -gt 96 ]; then
236 40e46009 Scott Ullrich
237 2ed3203c Scott Ullrich
	cat >>/usr/local/lib/php.ini <<EOF
238 e83dca8c Scott Ullrich
239 4b29393a Scott Ullrich
; APC Settings
240 40e46009 Scott Ullrich
apc.enabled="1"
241 59218e22 Scott Ullrich
apc.enable_cli="0"
242 de96a790 Scott Ullrich
apc.shm_size="${APCSHMEMSIZE}"
243 40e46009 Scott Ullrich
244 a8e61346 Ermal
[suhosin]
245
suhosin.get.max_array_depth = 5000
246
suhosin.get.max_array_index_length = 256
247
suhosin.get.max_vars = 5000
248 4f1bace5 Ermal
suhosin.get.max_value_length = 500000
249 a8e61346 Ermal
suhosin.post.max_array_depth = 5000
250
suhosin.post.max_array_index_length = 256
251
suhosin.post.max_vars = 5000
252 4f1bace5 Ermal
suhosin.post.max_value_length = 500000
253 a8e61346 Ermal
suhosin.request.max_array_depth = 5000
254
suhosin.request.max_array_index_length = 256
255
suhosin.request.max_vars = 5000
256 4f1bace5 Ermal
suhosin.request.max_value_length = 500000
257 a8e61346 Ermal
258 40e46009 Scott Ullrich
EOF
259
260 de96a790 Scott Ullrich
else 
261
262
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
263
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | logger -p daemon.info -i -t rc.php_ini_setup
264
265 40e46009 Scott Ullrich
fi
266
267 de96a790 Scott Ullrich
# Copy php.ini file to etc/ too (cli)
268 40e46009 Scott Ullrich
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
269 e1fda0c0 Scott Ullrich
270
# Remove old log file if it exists.
271
if [ -f /var/run/php_modules_load_errors.txt ]; then
272
	rm /var/run/php_modules_load_errors.txt
273
fi 
274
275 7030262c Scott Ullrich
for EXT in $PHPMODULES; do
276
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | tr '[:upper:]' '[:lower:]'`"
277
done
278
279 e1fda0c0 Scott Ullrich
# Check loaded modules and remove anything that did not load correctly
280 90108d90 Scott Ullrich
LOADED_MODULES=`php -m | tr '[:upper:]' '[:lower:]' 2>/dev/null | grep -v "\["`
281 7030262c Scott Ullrich
for EXT in $PHPMODULESLC; do
282 e1fda0c0 Scott Ullrich
	SHOULDREMOVE="true"
283
	for LM in $LOADED_MODULES; do
284
		if [ "$EXT" = "$LM" ]; then
285
			SHOULDREMOVE="false"
286
		fi		
287
	done
288 1e86e897 Scott Ullrich
	# Handle low memory situations
289 8ee1dc80 Scott Ullrich
	if [ "$LOWMEM" = "TRUE" ]; then
290
		if [ "$EXT" = "apc" ]; then
291
			SHOULDREMOVE="true"
292
		fi
293
		if [ "$EXT" = "xcache" ]; then
294
			SHOULDREMOVE="true"
295
		fi
296
	fi
297 e1fda0c0 Scott Ullrich
	if [ "$SHOULDREMOVE" = "true" ]; then
298
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
299
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
300
			cat /usr/local/lib/php.ini | grep -v $EXT > /tmp/php.ini
301
			mv /tmp/php.ini /usr/local/lib/php.ini
302
		fi
303
	fi
304
done
305
306
# Copy php.ini file to etc/ too (cli)
307
cp /usr/local/lib/php.ini /usr/local/etc/php.ini
308
309
310