Project

General

Profile

Download (9.34 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
#	rc.php_ini_setup
4
#	Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
5
#	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

    
28
# Set our operating platform
29
PLATFORM=`/bin/cat /etc/platform`
30

    
31
if [ -d /usr/local/lib/php/20090626 ]; then
32
	EXTENSIONSDIR="/usr/local/lib/php/20090626/"
33
else
34
	EXTENSIONSDIR="/usr/local/lib/php/20060613/"
35
fi
36

    
37
# Grab amount of memory that is detected
38
if [ -f /var/log/dmesg.boot ]; then
39
	AVAILMEM=`/bin/cat /var/log/dmesg.boot |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
40
else 
41
	AVAILMEM=`/sbin/dmesg -a |/usr/bin/awk '/avail memory/ { memory=($4 / 1048576); printf("%0.0f\n", memory); exit}'`
42
fi
43

    
44
if [ -z "$AVAILMEM" ]; then
45
	MEM=`/sbin/sysctl hw.physmem | cut -d':' -f2`
46
	AVAILMEM=`/bin/expr $MEM / 1048576`
47
fi
48

    
49
# Calculate APC SHM size according 
50
# to detected memory values
51
if [ "$AVAILMEM" -lt "65" ]; then
52
	APCSHMEMSIZE="1M"
53
fi
54
if [ "$AVAILMEM" -lt "96" ]; then
55
	APCSHMEMSIZE="5M"
56
fi
57
if [ "$AVAILMEM" -lt "128" ]; then
58
	APCSHMEMSIZE="10M"
59
fi
60
if [ "$AVAILMEM" -gt "128" ]; then
61
	APCSHMEMSIZE="15M"
62
fi
63
if [ "$AVAILMEM" -gt "256" ]; then
64
	APCSHMEMSIZE="20M"
65
fi
66
if [ "$AVAILMEM" -gt "384" ]; then
67
	APCSHMEMSIZE="25M"
68
fi
69
if [ "$AVAILMEM" -gt "512" ]; then
70
	APCSHMEMSIZE="30M"
71
fi
72
if [ "$AVAILMEM" -gt "784" ]; then
73
	APCSHMEMSIZE="35M"
74
fi
75

    
76
# Set upload directory
77
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
78
	UPLOADTMPDIR="/root"
79
else 
80
	UPLOADTMPDIR="/tmp"
81
fi
82

    
83
# Define php modules.  Do not add .so, it will  
84
# be done automatically by the script below.
85
PHPMODULES="apc"
86
PHPMODULES="$PHPMODULES standard"
87
# Downloading via HTTP/FTP (pkg mgr, etc)
88
PHPMODULES="$PHPMODULES curl date"
89
# Internationalization 
90
PHPMODULES="$PHPMODULES gettext"
91
# User manager
92
PHPMODULES="$PHPMODULES ldap openssl pcntl"
93
PHPMODULES="$PHPMODULES mhash"
94
PHPMODULES="$PHPMODULES mcrypt"
95
# Regexs, PERL style!
96
PHPMODULES="$PHPMODULES pcre"
97
# The mighty posix!
98
PHPMODULES="$PHPMODULES posix"
99
PHPMODULES="$PHPMODULES readline"
100
# Login sessions
101
PHPMODULES="$PHPMODULES session"
102
# Extra sanity seatbelts
103
PHPMODULES="$PHPMODULES suhosin"
104
# Firewall rules edit
105
PHPMODULES="$PHPMODULES ctype"
106
# Config read/write
107
PHPMODULES="$PHPMODULES xml xmlreader xmlwriter libxml"
108
PHPMODULES="$PHPMODULES simplexml"
109
# firewall_rules_edit.php
110
PHPMODULES="$PHPMODULES mbstring"
111
# Synchronization primitives
112
PHPMODULES="$PHPMODULES shmop"
113
# Page compression
114
PHPMODULES="$PHPMODULES zlib"
115
# SQLlite & Database
116
PHPMODULES="$PHPMODULES spl"
117
PHPMODULES="$PHPMODULES pdo"
118
PHPMODULES="$PHPMODULES sqlite"
119
# ZeroMQ
120
PHPMODULES="$PHPMODULES zmq"
121
# SSH2
122
PHPMODULES="$PHPMODULES ssh2"
123
# pfSense extensions
124
PHPMODULES="$PHPMODULES pfSense"
125

    
126
PHP_ZEND_MODULES="ioncube_loader"
127
PHP_ZEND_MODULES_TS="ioncube_loader_ts"
128

    
129
# Modules previously included.
130
# can be turned on by touching
131
# /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
#	json \
143

    
144
# Clear the .ini file to make sure we are clean
145
if [ -f /usr/local/etc/php.ini ]; then
146
	/bin/rm /usr/local/etc/php.ini
147
fi
148
if [ -f /usr/local/lib/php.ini ]; then
149
	/bin/rm /usr/local/lib/php.ini
150
fi
151
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/grep -v "\["`
152

    
153
# Get a loaded module list in the stock php
154
# Populate a dummy php.ini to avoid
155
# the file being clobbered and the firewall
156
# not being able to boot back up.
157
/bin/cat >/usr/local/lib/php.ini <<EOF
158
; File generated from /etc/rc.php_ini_setup
159
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
set_time_limit = 0
166
register_argc_argv = On
167
file_uploads = On
168
upload_tmp_dir = ${UPLOADTMPDIR}
169
upload_max_filesize = 100M
170
post_max_size = 100M
171
html_errors = Off
172
zlib.output_compression = Off
173
zlib.output_compression_level = 1
174
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
175
;display_startup_errors=off
176
;display_errors=off
177
log_errors=on
178
error_log=/tmp/PHP_errors.log
179
extension_dir=${EXTENSIONSDIR}
180

    
181
; Extensions
182

    
183
EOF
184

    
185
# Copy php.ini file to etc/ too (cli)
186
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
187

    
188
# Ensure directory exists
189
if [ ! -d /etc/php_dynamodules ]; then
190
	/bin/mkdir /etc/php_dynamodules
191
fi
192
if [ ! -d /etc/php_dynamodules_zend ]; then
193
	/bin/mkdir /etc/php_dynamodules_zend
194
fi
195
if [ ! -d /etc/php_dynamodules_zend_ts ]; then
196
	/bin/mkdir /etc/php_dynamodules_zend_ts
197
fi
198

    
199
# Read in dynamodules
200
if [ -d /etc/php_dynamodules ]; then
201
	DYNA_MODULES=`/bin/ls -Utr /etc/php_dynamodules/`
202
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
203
fi
204

    
205
# Read in zend modules
206
if [ -d /etc/php_dynamodules_zend ]; then
207
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend/`
208
	PHP_ZEND_MODULES="$PHP_ZEND_MODULES $DYNA_MODULES"
209
fi
210

    
211
# Read in zend threaded modules
212
if [ -d /etc/php_dynamodules_zend_ts ]; then
213
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules_zend_ts/`
214
	PHP_ZEND_MODULES_TS="$PHP_ZEND_MODULES_TS $DYNA_MODULES"
215
fi
216

    
217
# Loop through and generate modules to load.
218
# Take into account modules built into php.
219
for EXT in $PHPMODULES; do
220
	SHOULDADD="true"
221
	# Check to see if module is compiled into php statically
222
	for LM in $LOADED_MODULES; do
223
		if [ "$EXT" = "$LM" ]; then
224
			SHOULDADD="false"
225
		fi
226
	done
227
	if [ "$SHOULDADD" = "true" ]; then
228
		# Ensure extension exists before adding.
229
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
230
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
231
		fi
232
	fi
233
done
234

    
235
# Zend modules
236
for EXT in $PHP_ZEND_MODULES; do
237
	# Ensure extension exists before adding.
238
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
239
		echo "zend_extension=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
240
	fi
241
done
242

    
243
# Zend threaded modules
244
for EXT in $PHP_ZEND_MODULES_TS; do
245
	# Ensure extension exists before adding.
246
	if [ -f "${EXTENSIONSDIR}/ioncube/${EXT}.so" ]; then
247
		echo "zend_extension_ts=${EXTENSIONSDIR}/ioncube/${EXT}.so" >> /usr/local/lib/php.ini
248
	fi
249
done
250

    
251
# Get amount of ram installed on this system
252
RAM=`/sbin/sysctl hw.realmem | /usr/bin/awk '{print $2/1000000}' | /usr/bin/awk -F '.' '{print $1}'`
253
export RAM
254
export LOWMEM
255
if [  "$RAM" -gt 96 ]; then
256

    
257
	/bin/cat >>/usr/local/lib/php.ini <<EOF
258

    
259
; APC Settings
260
apc.enabled="1"
261
apc.enable_cli="0"
262
apc.shm_size="${APCSHMEMSIZE}"
263

    
264
EOF
265

    
266
else
267
	LOWMEM="TRUE"
268
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
269
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | /usr/bin/logger -p daemon.info -i -t rc.php_ini_setup
270
fi
271

    
272
	/bin/cat >>/usr/local/lib/php.ini <<EOF
273

    
274
[suhosin]
275
suhosin.get.max_array_depth = 5000
276
suhosin.get.max_array_index_length = 256
277
suhosin.get.max_vars = 5000
278
suhosin.get.max_value_length = 500000
279
suhosin.post.max_array_depth = 5000
280
suhosin.post.max_array_index_length = 256
281
suhosin.post.max_vars = 5000
282
suhosin.post.max_value_length = 500000
283
suhosin.request.max_array_depth = 5000
284
suhosin.request.max_array_index_length = 256
285
suhosin.request.max_vars = 5000
286
suhosin.request.max_value_length = 500000
287
suhosin.memory_limit = 512435456
288

    
289
EOF
290

    
291

    
292
# Copy php.ini file to etc/ too (cli)
293
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
294

    
295
# Remove old log file if it exists.
296
if [ -f /var/run/php_modules_load_errors.txt ]; then
297
	/bin/rm /var/run/php_modules_load_errors.txt
298
fi 
299

    
300
for EXT in $PHPMODULES; do
301
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]'`"
302
done
303

    
304
# Check loaded modules and remove anything that did not load correctly
305
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\["`
306
for EXT in $PHPMODULESLC; do
307
	SHOULDREMOVE="true"
308
	for LM in $LOADED_MODULES; do
309
		if [ "$EXT" = "$LM" ]; then
310
			SHOULDREMOVE="false"
311
		fi		
312
	done
313
	# Handle low memory situations
314
	if [ "$LOWMEM" = "TRUE" ]; then
315
		if [ "$EXT" = "apc" ]; then
316
			SHOULDREMOVE="true"
317
		fi
318
		if [ "$EXT" = "xcache" ]; then
319
			SHOULDREMOVE="true"
320
		fi
321
	fi
322
	if [ "$SHOULDREMOVE" = "true" ]; then
323
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
324
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
325
			/bin/cat /usr/local/lib/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
326
			/bin/rm -f /usr/local/lib/php.ini
327
			/bin/mv /tmp/php.ini /usr/local/lib/php.ini
328
		fi
329
	fi
330
done
331

    
332
# Copy php.ini file to etc/ too (cli)
333
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
(81-81/106)