Project

General

Profile

Download (8.04 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
EXTENSIONSDIR="/usr/local/lib/php/20060613/"
31

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

    
39
if [ -z "$AVAILMEM" ]; then
40
	MEM=`/sbin/sysctl hw.physmem | cut -d':' -f2`
41
	AVAILMEM=`/bin/expr $MEM / 1048576`
42
fi
43

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

    
71
# Set upload directory
72
if [ "$PLATFORM" = "embedded" -o "$PLATFORM" = "nanobsd" ]; then
73
	UPLOADTMPDIR="/root"
74
else 
75
	UPLOADTMPDIR="/tmp"
76
fi
77

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

    
120
# Modules previously included.
121
# can be turned on by touching
122
# /etc/php_dynamodules/$modulename
123
#	sysvmsg \
124
#	sysvsem \
125
#	sysvshm \
126
#	bcmath \
127
#	tokenizer \
128
#	uploadprogress \
129
#	sockets \
130
#	Reflection \
131
#	mysql \
132
#	bz2	\
133
#	json \
134

    
135
# Clear the .ini file to make sure we are clean
136
if [ -f /usr/local/etc/php.ini ]; then
137
	/bin/rm /usr/local/etc/php.ini
138
fi
139
if [ -f /usr/local/lib/php.ini ]; then
140
	/bin/rm /usr/local/lib/php.ini
141
fi
142
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/grep -v "\["`
143

    
144
# Get a loaded module list in the stock php
145
# Populate a dummy php.ini to avoid
146
# the file being clobbered and the firewall
147
# not being able to boot back up.
148
/bin/cat >/usr/local/lib/php.ini <<EOF
149
; File generated from /etc/rc.php_ini_setup
150
output_buffering = "0"
151
expose_php = Off
152
implicit_flush = true
153
magic_quotes_gpc = Off
154
max_execution_time = 99999999
155
max_input_time = 99999999
156
set_time_limit = 0
157
register_argc_argv = On
158
file_uploads = On
159
upload_tmp_dir = ${UPLOADTMPDIR}
160
upload_max_filesize = 100M
161
post_max_size = 100M
162
html_errors = Off
163
zlib.output_compression = Off
164
zlib.output_compression_level = 1
165
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
166
extension_dir=${EXTENSIONSDIR}
167

    
168
; Extensions
169

    
170
EOF
171

    
172
# Copy php.ini file to etc/ too (cli)
173
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
174

    
175
# Ensure directory exists
176
if [ ! -d /etc/php_dynamodules ]; then
177
	/bin/mkdir /etc/php_dynamodules
178
fi
179

    
180
# Read in dynamodules
181
if [ -d /etc/php_dynamodules ]; then
182
	DYNA_MODULES=`/bin/ls /etc/php_dynamodules/`
183
	PHPMODULES="$PHPMODULES $DYNA_MODULES"
184
fi
185

    
186
# Loop through and generate modules to load.
187
# Take into account modules built into php.
188
for EXT in $PHPMODULES; do
189
	SHOULDADD="true"
190
	# Check to see if module is compiled into php statically
191
	for LM in $LOADED_MODULES; do
192
		if [ "$EXT" = "$LM" ]; then
193
			SHOULDADD="false"
194
		fi
195
	done
196
	if [ "$SHOULDADD" = "true" ]; then
197
		# Ensure extension exists before adding.
198
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
199
			echo "extension=${EXT}.so" >> /usr/local/lib/php.ini
200
		fi
201
	fi
202
done
203

    
204
# Get amount of ram installed on this system
205
RAM=`/sbin/sysctl hw.realmem | /usr/bin/awk '{print $2/1000000}' | /usr/bin/awk -F '.' '{print $1}'`
206
export RAM
207
export LOWMEM
208
if [  "$RAM" -gt 96 ]; then
209

    
210
	/bin/cat >>/usr/local/lib/php.ini <<EOF
211

    
212
; APC Settings
213
apc.enabled="1"
214
apc.enable_cli="0"
215
apc.shm_size="${APCSHMEMSIZE}"
216

    
217
EOF
218

    
219
else
220
	LOWMEM="TRUE"
221
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC."
222
	echo ">>> WARNING!  under 128 megabytes of ram detected.  Not enabling APC." | /usr/bin/logger -p daemon.info -i -t rc.php_ini_setup
223
fi
224

    
225
	/bin/cat >>/usr/local/lib/php.ini <<EOF
226

    
227
[suhosin]
228
suhosin.get.max_array_depth = 5000
229
suhosin.get.max_array_index_length = 256
230
suhosin.get.max_vars = 5000
231
suhosin.get.max_value_length = 500000
232
suhosin.post.max_array_depth = 5000
233
suhosin.post.max_array_index_length = 256
234
suhosin.post.max_vars = 5000
235
suhosin.post.max_value_length = 500000
236
suhosin.request.max_array_depth = 5000
237
suhosin.request.max_array_index_length = 256
238
suhosin.request.max_vars = 5000
239
suhosin.request.max_value_length = 500000
240
suhosin.memory_limit = 512435456
241

    
242
EOF
243

    
244

    
245
# Copy php.ini file to etc/ too (cli)
246
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
247

    
248
# Remove old log file if it exists.
249
if [ -f /var/run/php_modules_load_errors.txt ]; then
250
	/bin/rm /var/run/php_modules_load_errors.txt
251
fi 
252

    
253
for EXT in $PHPMODULES; do
254
	PHPMODULESLC="$PHPMODULESLC `echo "$EXT" | /usr/bin/tr '[:upper:]' '[:lower:]'`"
255
done
256

    
257
# Check loaded modules and remove anything that did not load correctly
258
LOADED_MODULES=`/usr/local/bin/php -m | /usr/bin/tr '[:upper:]' '[:lower:]' 2>/dev/null | /usr/bin/grep -v "\["`
259
for EXT in $PHPMODULESLC; do
260
	SHOULDREMOVE="true"
261
	for LM in $LOADED_MODULES; do
262
		if [ "$EXT" = "$LM" ]; then
263
			SHOULDREMOVE="false"
264
		fi		
265
	done
266
	# Handle low memory situations
267
	if [ "$LOWMEM" = "TRUE" ]; then
268
		if [ "$EXT" = "apc" ]; then
269
			SHOULDREMOVE="true"
270
		fi
271
		if [ "$EXT" = "xcache" ]; then
272
			SHOULDREMOVE="true"
273
		fi
274
	fi
275
	if [ "$SHOULDREMOVE" = "true" ]; then
276
		if [ -f "${EXTENSIONSDIR}${EXT}.so" ]; then
277
			echo ">>> ${EXT} did not load correctly.  Removing from php.ini..." >> /var/run/php_modules_load_errors.txt
278
			/bin/cat /usr/local/lib/php.ini | /usr/bin/grep -v $EXT > /tmp/php.ini
279
			/bin/rm -f /usr/local/lib/php.ini
280
			/bin/mv /tmp/php.ini /usr/local/lib/php.ini
281
		fi
282
	fi
283
done
284

    
285
# Copy php.ini file to etc/ too (cli)
286
/bin/cp /usr/local/lib/php.ini /usr/local/etc/php.ini
(78-78/102)